mardi 5 mai 2015

Array won't print out results

I am attempting to put information into an array and print it out. I am making a game, but I'm not sure why it won't print. At most, the result is (null).

I am trying to put *firstItem into the denizen's inventory

 Denizen *firstDen = [[[Denizen alloc] initWithName:@"Mom," andHealth:4] autorelease];
    [bedroom spawn:firstDen];

 Item *firstItem = [[[Item alloc] initWithName:@"Stick" andWeight:8 andVolume:2 andDurability:1 andWorth:5] autorelease];
    [bedroom drop:firstItem];

 [firstDen addItemToInventory:firstItem];

then retrieve it using:

-(void)getWares
{
    NSArray *denInventoryItems = [wares allKeys];
    [self outputMessage: [NSString stringWithFormat:@"\nThese are the following items for sale: %@ \n.", [denInventoryItems componentsJoinedByString:@" "]]];
}

Here is my addItemToInventory where I suspect where the problem may lie, but I'm not sure. When I use a breakpoint it shows that firstItem is in wares, but nothing shows when I call getWares

-(void)addItemToInventory:(Item *)toAdd
{
    [wares addObject:toAdd];
}

Thank you very much for the help.

Aucun commentaire:

Enregistrer un commentaire