7 Replies - 3996 Views - Last Post: 13 April 2014 - 09:24 AM Rate Topic: -----

#1 appleweed   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 11-April 14

need help with text based game

Posted 11 April 2014 - 04:20 PM

I am trying to make a text based game. the game has been working perfectly setting up the rooms, first couple of commands, and running it. I am now trying to add items to it but every time it try to run the game it returns
java.lang.NullPointerException
at Room.addItem(Room.java:107)
at Game.createRooms(Game.java:133)
at Game.<init>(Game.java:28)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
at bluej.runtime.ExecServer$3.run(ExecServer.java:740)

here are the classses that matter for this particular situation
import java.util.HashMap;
/**
 *
 * 
 * @version 04-11-2014
 */
public class Item
{
    private HashMap<String, Item> itemList;
    private String name;
    private String itemDescription;


    /**
     * creates an item object
     * @param name
     * @param itemDescription
     */
    public Item(String name, String itemDescription)
    {
        this.name = name;
        this.itemDescription = itemDescription;
        itemList = new HashMap<String, Item>();
    }
    

    /**
     * add the items to the game
     */
    public void addItems()
    {
       itemList.put("trident", new Item("trident", "poseidens Trident"));
       itemList.put("dubloons", new Item("dubloons", "5 dubloons"));
       itemList.put("seaweed", new Item("seaweed", "youd think this stuff would be cheaper"));
    }
       public String getItemName(){
   return name;
}
        
    public String getItemDescription()
    {
        return itemDescription;
    }
    
}



import java.util.Set;
import java.util.HashMap;
import java.util.Iterator;

/**
 * Class Room - a room in an adventure game.
 *
 *
 * A "Room" represents one location in the scenery of the game.  It is 
 * connected to other rooms via exits.  For each existing exit, the room 
 * stores a reference to the neighboring room.
 * 
 * 
 */

public class Room 
{
    private String description;
    private HashMap<String, Room> exits;        // stores exits of this room.
    private HashMap<String, Item> itemList;
    private String name;
    private String itemDescription;
    

    /**
     * Create a room described "description". Initially, it has
     * no exits. "description" is something like "a kitchen" or
     * "an open court yard".
     * @param description The room's description.
     */
    public Room(String description) 
    {
        this.description = description;
        exits = new HashMap<String, Room>();
        
    }
    
    public Room(String description, Item roomItem)
    {
        this.description = description;
        exits = new HashMap<String, Room>();
        itemList= new HashMap<String,Item>();
        this.name = name;
        this.itemDescription = itemDescription;
}   

    /**
     * Define an exit from this room.
     * @param direction The direction of the exit.
     * @param neighbor  The room to which the exit leads.
     */
    public void setExit(String direction, Room neighbor) 
    {
        exits.put(direction, neighbor);
    }

    /**
     * @return The short description of the room
     * (the one that was defined in the constructor).
     */
    public String getShortDescription()
    {
        return description;
    }

    /**
     * Return a description of the room in the form:
     *     You are in the kitchen.
     *     Exits: north west
     * @return A long description of this room
     */
    public String getLongDescription()
    {
        return "You are " + description + ".\n" + getExitString();
    }

    /**
     * Return a string describing the room's exits, for example
     * "Exits: north west".
     * @return Details of the room's exits.
     */
    private String getExitString()
    {
        String returnString = "Exits:";
        Set<String> keys = exits.keySet();
        for(String exit : keys) {
            returnString += " " + exit;
        }
        return returnString;
    }

    /**
     * Return the room that is reached if we go from this room in direction
     * "direction". If there is no room in that direction, return null.
     * @param direction The exit's direction.
     * @return The room in the given direction.
     */
    public Room getExit(String direction) 
    {
        return exits.get(direction);
    }
    public void addItem(Item item)
    {
        itemList.put(item.getItemName(), new Item(item.getItemName(), item.getItemDescription()));
    }
    public String getItemDescription(){
        return itemDescription;
}

}


/**
 * 
 */

public class Game 
{
    private Parser parser;
    private Room currentRoom;
    private Item seaweed;
    /**
     * Create the game and initialise its internal map.
     */
    public Game() 
    {
        createRooms();
        parser = new Parser();
        seaweed = new Item("seaweed", "smells weird");
    }

    /**
     * Create all the rooms and link their exits together.
     */
   private void createRooms()
    {
        Room oceanGrotto, outsideFortress, fortressWallEast, fortressWallWest,
                insideFortress, secretTunnel, tunnelEnd, bavesStable, sunkenShip, 
                caviarUniversity, parkingLot, murkeyWaters, otterOasis,
                mysteriousCloud, dryLands, caveEntrance, caveInside,
                darkCrevace, crevaceDown, crevaceBottom;
      
        // create the rooms
        oceanGrotto = new Room("in the whales territory");
        outsideFortress = new Room("the gate of the sharks fortress");
        fortressWallEast = new Room("The eastern stone wall of the fortress");
        fortressWallWest = new Room("western stone wall of the fortress");
        insideFortress = new Room("inside the fortress");
        secretTunnel = new Room("inside the hidden tunnel");
        tunnelEnd = new Room("end of the tunnel");
        bavesStable = new Room("the seahorses house");
        sunkenShip = new Room("a sunken ship");
        caviarUniversity = new Room("Fish school");
        parkingLot = new Room("parking lot behind the school");
        murkeyWaters = new Room("Polluted waters");
        otterOasis = new Room ("Home of the otters");
        mysteriousCloud = new Room("a mysterious cloud above the water");
        dryLands = new Room("area above the ocean");
        caveEntrance = new Room("entrance to the abandoned cave");
        caveInside = new Room("inside  the cave");
        darkCrevace = new Room("a dark hole in the ground");
        crevaceDown = new Room ("deep in the dark crevace");
        crevaceBottom = new Room("the bottom of the crevace");
        
        // initialise room exits
        oceanGrotto.setExit("east", murkeyWaters);
        oceanGrotto.setExit("south", caviarUniversity);
        oceanGrotto.setExit("west", bavesStable);
        oceanGrotto.setExit("north", outsideFortress);
        
        //Add extra exit DOWN later
        bavesStable.setExit("east", oceanGrotto);
        bavesStable.setExit("south", sunkenShip);
        bavesStable.setExit("north", fortressWallWest);
        
        secretTunnel.setExit("north", tunnelEnd);
        secretTunnel.setExit("up", bavesStable);
        
        tunnelEnd.setExit("south", secretTunnel);
        
        fortressWallWest.setExit("south", bavesStable);
        fortressWallWest.setExit("east", outsideFortress);
        
        fortressWallEast.setExit("south", murkeyWaters);
        fortressWallEast.setExit("west", outsideFortress);
        
        //Add extra Exit North later
        outsideFortress.setExit("south", oceanGrotto);
        outsideFortress.setExit("east", fortressWallEast);
        outsideFortress.setExit("west", fortressWallWest);
        
        sunkenShip.setExit("north", bavesStable);
        sunkenShip.setExit("east", caviarUniversity);
        
        //Add extraExit south later
        caviarUniversity.setExit("north", oceanGrotto);
        caviarUniversity.setExit("east", otterOasis);
        caviarUniversity.setExit("west", sunkenShip);
        
        parkingLot.setExit("north", caviarUniversity);
        
        murkeyWaters.setExit("north", fortressWallEast);
        murkeyWaters.setExit("east", caveEntrance);
        murkeyWaters.setExit("south", otterOasis);
        murkeyWaters.setExit("west", oceanGrotto);
        
        otterOasis.setExit("north", murkeyWaters);
        otterOasis.setExit("east", darkCrevace);
        otterOasis.setExit("south", mysteriousCloud);
        otterOasis.setExit("west", caviarUniversity);
        
        mysteriousCloud.setExit("north", otterOasis);
        mysteriousCloud.setExit("up", dryLands);
        
        caveEntrance.setExit("east", caveInside);
        caveEntrance.setExit("west", murkeyWaters);
        
        caveInside.setExit("west", caveEntrance);
        
        darkCrevace.setExit("west", otterOasis);
        darkCrevace.setExit("down", crevaceDown);
        
        //Add extra exit DOWN later
        crevaceDown.setExit("up", darkCrevace);
        
        crevaceBottom.setExit("up", crevaceDown);
        
        dryLands.setExit("down", mysteriousCloud);
        
        
        currentRoom = oceanGrotto;  // start game in the whales territory
        oceanGrotto.addItem(seaweed);
    }

    /**
     *  Main play routine.  Loops until end of play.
     */
    public void play() 
    {            
        printWelcome();

        // Enter the main command loop.  Here we repeatedly read commands and
        // execute them until the game is over.

        boolean finished = false;
        while (! finished) {
            Command command = parser.getCommand();
            finished = processCommand(command);
        }
        System.out.println("Thank you for playing.  Good bye.");
    }

    /**
     * Print out the opening message for the player.
     */
    private void printWelcome()
    {
        System.out.println();
        System.out.println("Welcome to the World of Zuul!");
        System.out.println("World of Zuul is a new, incredibly boring adventure game.");
        System.out.println("Type 'help' if you need help.");
        System.out.println();
        System.out.println(currentRoom.getLongDescription());
    }

    /**
     * Given a command, process (that is: execute) the command.
     * @param command The command to be processed.
     * @return true If the command ends the game, false otherwise.
     */
    private boolean processCommand(Command command) 
    {
        boolean wantToQuit = false;

        CommandWord commandWord = command.getCommandWord();

        switch (commandWord) {
            case UNKNOWN:
                System.out.println("I don't know what you mean...");
                break;

            case HELP:
                printHelp();
                break;

            case SWIM:
                swimRoom(command);
                break;

            case QUIT:
                wantToQuit = quit(command);
                break;
            
            case LOOK:
                System.out.println(currentRoom.getLongDescription());
                System.out.println(currentRoom.getItemDescription());
                break;
        }
        return wantToQuit;
    }

    // implementations of user commands:

    /**
     * Print out some help information.
     * Here we print some stupid, cryptic message and a list of the 
     * command words.
     */
    private void printHelp() 
    {
        System.out.println("You are lost. You are alone. You wander");
        System.out.println("around the ocean flo'.");
        System.out.println();
        System.out.println("Your command words are:");
        parser.showCommands();
    }

    /** 
     * Try to go in one direction. If there is an exit, enter the new
     * room, otherwise print an error message.
     */
    private void swimRoom(Command command) 
    {
        if(!command.hasSecondWord()) {
            // if there is no second word, we don't know where to go...
            System.out.println("Swim where?");
            return;
        }

        String direction = command.getSecondWord();

        // Try to leave current room.
        Room nextRoom = currentRoom.getExit(direction);

        if (nextRoom == null) {
            System.out.println("There is no door!");
        }
        else {
            currentRoom = nextRoom;
            System.out.println(currentRoom.getLongDescription());
        }
    }

    /** 
     * "Quit" was entered. Check the rest of the command to see
     * whether we really quit the game.
     * @return true, if this command quits the game, false otherwise.
     */
    private boolean quit(Command command) 
    {
        if(command.hasSecondWord()) {
            System.out.println("Quit what?");
            return false;
        }
        else {
            return true;  // signal that we want to quit
        }
    }
}



i know that it is the line
itemList.put(item.getItemName(), new Item(item.getItemName(), item.getItemDescription()));
in the game class that is causing the nullpointer exception i just really cant figure out why that keeps happening and how to add the values correctly

Is This A Good Question/Topic? 0
  • +

Replies To: need help with text based game

#2 Sheph   User is offline

  • D.I.C Lover
  • member icon

Reputation: 447
  • View blog
  • Posts: 1,032
  • Joined: 12-October 11

Re: need help with text based game

Posted 11 April 2014 - 04:47 PM

When you use the Room constructor with a single String parameter, you don't initialize your itemList HashMap for that particular Room object.
Was This Post Helpful? 0
  • +
  • -

#3 appleweed   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 11-April 14

Re: need help with text based game

Posted 11 April 2014 - 05:36 PM

after adding the second item parameter to the current room
 oceanGrotto = new Room("in the whales territory", seaweed);

it is still giving the same error. I cant understand this because that is the only room that is using the addItem method
Was This Post Helpful? 0
  • +
  • -

#4 Sheph   User is offline

  • D.I.C Lover
  • member icon

Reputation: 447
  • View blog
  • Posts: 1,032
  • Joined: 12-October 11

Re: need help with text based game

Posted 12 April 2014 - 06:54 AM

A little debugging: I put a System.out.println() statement directly above the line that was causing the problem and printed out the parameter, "item" to find that it was null. That means seaweed is null when you pass it in. This is because you call createRooms() in the Game constructor BEFORE you initialize seaweed.

Some other things to keep in mind: You will want to clean up the room constructors so that they both achieve something similar and initialize most of the data structures with what they are given. (ie, initialize the HashMap anyway in the first constructor, and take away the redundant assignments for itemDescription and name.) createRooms is getting pretty big. Consider a populateRooms() method now. Lastly, what is the point of having a HashMap of Items in the Item class? If you are trying to keep a global reference to all the items, consider putting the HashMap in Game or another class, and let the Item class worry about just the name and description.
Was This Post Helpful? 0
  • +
  • -

#5 appleweed   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 11-April 14

Re: need help with text based game

Posted 12 April 2014 - 08:44 AM

so ive been editing it and you were right the hashmap for the items was completely unneccessary so i changed that to string. im trying to make an addItem and getItem methods in the Room class that i can call in the Game class. Im using an arrayList for the items (but im not sure if that is even neccessary since each room will only have one item). But i will be needing it for the players inventory when they pick up the items. i am having severe difficulty figuring this one out even though i feel like the answer is really simple. this is what i have so far

public class Item{
private String itemName;

public Item(String itemName){
this.itemName = itemName;

}

public String getItemName(){
return itemName;
}
}


import java.util.Set;
import java.util.HashMap;
import java.util.Iterator;
import java.util.ArrayList;
/**
 * Class Room - a room in an adventure game.
 *
 * This class is part of the "World of Zuul" application. 
 * "World of Zuul" is a very simple, text based adventure game.  
 *
 * A "Room" represents one location in the scenery of the game.  It is 
 * connected to other rooms via exits.  For each existing exit, the room 
 * stores a reference to the neighboring room.
 * 
 * @author  Michael Kölling and David J. Barnes
 * @version 2011.08.09
 */

public class Room 
{
    private String description;
    private HashMap<String, Room> exits;        // stores exits of this room.
    private HashMap<String, Item> itemList;
    private String name;
    private ArrayList<Item> items;
    

    /**
     * Create a room described "description". Initially, it has
     * no exits. "description" is something like "a kitchen" or
     * "an open court yard".
     * @param description The room's description.
     */
   
    
   public Room(String description) 
    {
        this.description = description;
        exits = new HashMap<String, Room>();
        items = new ArrayList<Item>();
    }
    /**
     * Define an exit from this room.
     * @param direction The direction of the exit.
     * @param neighbor  The room to which the exit leads.
     */
    public void setExit(String direction, Room neighbor) 
    {
        exits.put(direction, neighbor);
    }
   
    /**
     * @return The short description of the room
     * (the one that was defined in the constructor).
     */
    public String getShortDescription()
    {
        return description;
    }

    /**
     * Return a description of the room in the form:
     *     You are in the kitchen.
     *     Exits: north west
     * @return A long description of this room
     */
    public String getLongDescription()
    {
        String longDescription = "You are " + description + ".\n" + getExitString();
        if(items.size() > 0) {
            longDescription += "\nThe following things are here: \n";
            for (Item item : items) {
                longDescription += "\t" + item.getItemName() + "\n";
            }
        }
        return longDescription;
            
    }

    /**
     * Return a string describing the room's exits, for example
     * "Exits: north west".
     * @return Details of the room's exits.
     */
    private String getExitString()
    {
        String returnString = "Exits:";
        Set<String> keys = exits.keySet();
        for(String exit : keys) {
            returnString += " " + exit;
        }
        return returnString;
    }

    /**
     * Return the room that is reached if we go from this room in direction
     * "direction". If there is no room in that direction, return null.
     * @param direction The exit's direction.
     * @return The room in the given direction.
     */
    public Room getExit(String direction) 
    {
        return exits.get(direction);
    }
  
    /**
     * Add an item to the room 
     */
    public void addItem(Item i){
        items.add(i);
    }
    public String getItem() {
       
    //THIS IS THE METHOD I CANT FIGURE OUT
    }
}


import java.util.ArrayList;
/**
 * 
 */

public class Game 
{
    private Parser parser;
    private Room currentRoom;
    private ArrayList<Item> inventory;
    private Item seaWeed;
    /**
     * Create the game and initialise its internal map.
     */
    public Game() 
    {
        
        inventory = new ArrayList<Item>();
        parser = new Parser();
        seaWeed = new Item("Seaweed");
        createRooms();
    }

    /**
     * Create all the rooms and link their exits together.
     */
   private void createRooms()
    {
        Room oceanGrotto, outsideFortress, fortressWallEast, fortressWallWest,
                insideFortress, secretTunnel, tunnelEnd, bavesStable, sunkenShip, 
                caviarUniversity, parkingLot, murkeyWaters, otterOasis,
                mysteriousCloud, dryLands, caveEntrance, caveInside,
                darkCrevace, crevaceDown, crevaceBottom;
      
        // create the rooms
        oceanGrotto = new Room("in the whales territory");
        outsideFortress = new Room("the gate of the sharks fortress");
        fortressWallEast = new Room("The eastern stone wall of the fortress");
        fortressWallWest = new Room("western stone wall of the fortress");
        insideFortress = new Room("inside the fortress");
        secretTunnel = new Room("inside the hidden tunnel");
        tunnelEnd = new Room("end of the tunnel");
        bavesStable = new Room("the seahorses house");
        sunkenShip = new Room("a sunken ship");
        caviarUniversity = new Room("Fish school");
        parkingLot = new Room("parking lot behind the school");
        murkeyWaters = new Room("Polluted waters");
        otterOasis = new Room ("Home of the otters");
        mysteriousCloud = new Room("a mysterious cloud above the water");
        dryLands = new Room("area above the ocean");
        caveEntrance = new Room("entrance to the abandoned cave");
        caveInside = new Room("inside  the cave");
        darkCrevace = new Room("a dark hole in the ground");
        crevaceDown = new Room ("deep in the dark crevace");
        crevaceBottom = new Room("the bottom of the crevace");
        
        // initialise room exits
        oceanGrotto.setExit("east", murkeyWaters);
        oceanGrotto.setExit("south", caviarUniversity);
        oceanGrotto.setExit("west", bavesStable);
        oceanGrotto.setExit("north", outsideFortress);
        
        //Add extra exit DOWN later
        bavesStable.setExit("east", oceanGrotto);
        bavesStable.setExit("south", sunkenShip);
        bavesStable.setExit("north", fortressWallWest);
        
        secretTunnel.setExit("north", tunnelEnd);
        secretTunnel.setExit("up", bavesStable);
        
        tunnelEnd.setExit("south", secretTunnel);
        
        fortressWallWest.setExit("south", bavesStable);
        fortressWallWest.setExit("east", outsideFortress);
        
        fortressWallEast.setExit("south", murkeyWaters);
        fortressWallEast.setExit("west", outsideFortress);
        
        //Add extra Exit North later
        outsideFortress.setExit("south", oceanGrotto);
        outsideFortress.setExit("east", fortressWallEast);
        outsideFortress.setExit("west", fortressWallWest);
        
        sunkenShip.setExit("north", bavesStable);
        sunkenShip.setExit("east", caviarUniversity);
        
        //Add extraExit south later
        caviarUniversity.setExit("north", oceanGrotto);
        caviarUniversity.setExit("east", otterOasis);
        caviarUniversity.setExit("west", sunkenShip);
        
        parkingLot.setExit("north", caviarUniversity);
        
        murkeyWaters.setExit("north", fortressWallEast);
        murkeyWaters.setExit("east", caveEntrance);
        murkeyWaters.setExit("south", otterOasis);
        murkeyWaters.setExit("west", oceanGrotto);
        
        otterOasis.setExit("north", murkeyWaters);
        otterOasis.setExit("east", darkCrevace);
        otterOasis.setExit("south", mysteriousCloud);
        otterOasis.setExit("west", caviarUniversity);
        
        mysteriousCloud.setExit("north", otterOasis);
        mysteriousCloud.setExit("up", dryLands);
        
        caveEntrance.setExit("east", caveInside);
        caveEntrance.setExit("west", murkeyWaters);
        
        caveInside.setExit("west", caveEntrance);
        
        darkCrevace.setExit("west", otterOasis);
        darkCrevace.setExit("down", crevaceDown);
        
        //Add extra exit DOWN later
        crevaceDown.setExit("up", darkCrevace);
        
        crevaceBottom.setExit("up", crevaceDown);
        
        dryLands.setExit("down", mysteriousCloud);
        
        //add items
        oceanGrotto.addItem(seaWeed);
        currentRoom = oceanGrotto;  // start game in the whales territory
        
       
    }
    
  
    /**
     *  Main play routine.  Loops until end of play.
     */
    public void play() 
    {            
        printWelcome();

        // Enter the main command loop.  Here we repeatedly read commands and
        // execute them until the game is over.

        boolean finished = false;
        while (! finished) {
            Command command = parser.getCommand();
            finished = processCommand(command);
        }
        System.out.println("Thank you for playing.  Good bye.");
    }

    /**
     * Print out the opening message for the player.
     */
    private void printWelcome()
    {
        System.out.println();
        System.out.println("Welcome to the World of Zuul!");
        System.out.println("World of Zuul is a new, incredibly boring adventure game.");
        System.out.println("Type 'help' if you need help.");
        System.out.println();
        System.out.println(currentRoom.getLongDescription());
    }

    /**
     * Given a command, process (that is: execute) the command.
     * @param command The command to be processed.
     * @return true If the command ends the game, false otherwise.
     */
    private boolean processCommand(Command command) 
    {
        boolean wantToQuit = false;

        CommandWord commandWord = command.getCommandWord();

        switch (commandWord) {
            case UNKNOWN:
                System.out.println("I don't know what you mean...");
                break;

            case HELP:
                printHelp();
                break;

            case SWIM:
                swimRoom(command);
                break;

            case QUIT:
                wantToQuit = quit(command);
                break;
            
            case LOOK:
                System.out.println(currentRoom.getLongDescription());
                system.out.println(currentRoom.getItem());
                break;
        }
        return wantToQuit;
    }

    // implementations of user commands:

    /**
     * Print out some help information.
     * Here we print some stupid, cryptic message and a list of the 
     * command words.
     */
    private void printHelp() 
    {
        System.out.println("You are lost. You are alone. You wander");
        System.out.println("around the ocean flo'.");
        System.out.println();
        System.out.println("Your command words are:");
        parser.showCommands();
    }

    /** 
     * Try to go in one direction. If there is an exit, enter the new
     * room, otherwise print an error message.
     */
    private void swimRoom(Command command) 
    {
        if(!command.hasSecondWord()) {
            // if there is no second word, we don't know where to go...
            System.out.println("Swim where?");
            return;
        }

        String direction = command.getSecondWord();

        // Try to leave current room.
        Room nextRoom = currentRoom.getExit(direction);

        if (nextRoom == null) {
            System.out.println("The water is too polluted, you cant go there!");
        }
        else {
            currentRoom = nextRoom;
            
    }
}
    /** 
     * "Quit" was entered. Check the rest of the command to see
     * whether we really quit the game.
     * @return true, if this command quits the game, false otherwise.
     */
    private boolean quit(Command command) 
    {
        if(command.hasSecondWord()) {
            System.out.println("Quit what?");
            return false;
        }
        else {
            return true;  // signal that we want to quit
        }
    }
   
}



as for createRooms i am well aware its getting big but i want the code to actually work before i clean it up
Was This Post Helpful? 0
  • +
  • -

#6 appleweed   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 11-April 14

Re: need help with text based game

Posted 12 April 2014 - 08:54 AM

I just figured that out i can now add items to the rooms.

 public String getItem() {
      
    return items.toString();
    }


ill keep posted on the next problem that happens.
Was This Post Helpful? 0
  • +
  • -

#7 Sheph   User is offline

  • D.I.C Lover
  • member icon

Reputation: 447
  • View blog
  • Posts: 1,032
  • Joined: 12-October 11

Re: need help with text based game

Posted 12 April 2014 - 08:55 AM

So just for the sake of everybody reading, were you able to clear up your first problem with the null pointer exception?

You are storing multiple items, and you are returning 1 item. There is obviously a discrepancy, but there are a couple ways to fix it. Either store just 1 and return 1, store multiple and return multiple (let game handle dividing them), or store multiple and choose 1 to return (the first one, the last one, a random one, etc.) I say for now, if one room can only have one item, you should just store one, until you decide to change it at some later point.
Was This Post Helpful? 0
  • +
  • -

#8 appleweed   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 11-April 14

Re: need help with text based game

Posted 13 April 2014 - 09:24 AM

yes i was thank you
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1