I am trying to add an item to a game that will "float" a player into the correct room. The code below is where the boat is added to a room and the the boolean newBoat is set to true:

        Item boat = new Item(" A boat to help you cross the lake \n", "boat", 10);
        newBoat = true;

Below is the method where I am trying to implement the command "float" which if the player has the boat and newBoat is true, currentRoom = roomFour;

    private void useBoat(Command command)
        if (newBoat = true) {
            currentRoom = roomFour;
            System.out.println("You have successfully crossed the lake");
        newBoat = false;
        if (newBoat = false) {
            System.out.println("You do not have a boat");

However, it will not set the currentRoom to roomFour but it will print out the line.

4 Years
Discussion Span
Last Post by JamesCherrill


First, you set newBoat to false on line 10 then try to see if it's false on line 11 - which ot always will be!

Second, on line 11 you have coded an assignment rather than an equality operator


Thank you for the help but after I use 'float', using the command 'look' results in an NPE.

     */private void look()

There's only one thing on that line that could cause an NPE and that's currentRoom - you;ll get an NPE when you try to use that when its null to call getLongDescription.
You'll have to look to the rest of your code and maybe add a few print sttements to find out why look() is being called when currentRoom is null

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.