in the class 'character' i want to set up an array of objects from the class 'item'
CODE
static item[] inventory = new item[51];
In the class 'item' variables are set up to keep track of information such as item names
CODE
static String itemName = "Big Cool Sword";
In my main program I want to change the value of one of these items
CODE
public static void main(String[] args) {
character hero = new character();
hero.inventory[1].itemName = "Bigger Cooler Sword";
}
But changing the value of
CODE
hero.inventory[1].itemName
to anything seems to change the value each
CODE
itemName
in the array, not just the
CODE
itemName
at position [1].
I know this because I output all the info with a call to
CODE
printCharacterInventory();
which is a function in the character class.
CODE
public void printCharacterInventory(){ // use this to print out inventory items
int count = 0;
while (count <= 50) {
System.out.println( "inventory " + count + ": " + " ********************");
System.out.println( "itemName: " + inventory[count].itemName );
}
My output lists "Bigger Cooler Sword" for each itemName, but I want only the itemName in hero.inventory[1] to be "Bigger Cooler Sword."
What in the world am I doing wrong?
If you are wondering why I only keep track of itemName, I removed a LOT of other variables to keep this post as short as possible.