![]() |
|
Some sort of array problem - Printable Version +- iDevGames Forums (http://www.idevgames.com/forums) +-- Forum: Development Zone (/forum-3.html) +--- Forum: Game Programming Fundamentals (/forum-7.html) +--- Thread: Some sort of array problem (/thread-5096.html) |
Some sort of array problem - Coin - Sep 2, 2005 01:17 PM Im not really sure what is going on an array (amebas) isnt holding the last object stuck into it, i think. After the last object is placed in the array, i can get info about it in that same method, but as soon as i try to call its methods from a different method everything is 0 whereas the other 3 objects are fine. here is my method for loading the objects into the array i dont think the beginning code matters much skip down the the note that says setup players Code: - (void)setupH:(int)h W:(int)w players:(int)plots of stuff in there that has nothing to do with it its basicallly the last loop the array amebas is the one that is giving me trouble. ameba has a method called -owner which returns the player that owns it as long as i am in the above method all 4 amebas in the amebas array tell me correctly which player owns them but as soon as its a diffferent method the last one is 0 for everything here is the method simple but if i log right before it and get the ameba n's owner it is -1 Code: - (id)amebaAt:(int)nQuote:2005-09-02 13:16:06.645 Ameba Wars[911] 0 0 yes amebas is init'd alloc'd and retain'd at -awakeFromNib Some sort of array problem - unknown - Sep 2, 2005 02:56 PM First thing that stikes out is Code: NSLog(@"%d %d", n, [[amebas objectAtIndex:n] owner]); // ownerI think id need to see the code for the amoeba class to really know what the problem is. Some sort of array problem - Coin - Sep 2, 2005 08:31 PM That -1 should be a 3 and it does the same thing for all accessor methods of the last added object, owner was just an example, the other 3 objects are fine so it isnt the ameba class. but here it is anyway Code: @implementation Amebaits just a bunch of mutator/accessor methods Some sort of array problem - unknown - Sep 3, 2005 01:04 AM Ok sorry I dont really see anything wrong. Is players 4 or 3? Some sort of array problem - Coin - Sep 3, 2005 12:59 PM Players 0-2 work fine but the last one in the array (3) is all -1s even if i log it at the end of the mehtod where it is created all 4 are fine, so something is happening to it. But i have no idea what i could try adding another and seeing what it does. Ill do that. Ok i made it just add an object and it did the same thign the last ogject was the messed up one 3 didnt have any problems. !!! here is my awake from nib method Code: - (void)awakeFromNibSome sort of array problem - Taxxodium - Sep 3, 2005 02:42 PM Don't alloc and retain, that's causing a memory leak. Do one of the following but not both: [[NSArray array] retain] OR [[NSArray alloc] init] Some sort of array problem - Coin - Sep 3, 2005 03:05 PM here is my new code, does the exact same thing Code: - (void)awakeFromNibthis gets the same thing also if i change it to amebas = [[NSMutableArray array] retain]; it gets the same thing as well |