You don't need to; just iterate over the array. Plus, if you want a linked list, you just need a pointer to the head node, a method to add new nodes, (possibly a method to remove nodes), and a method to walk the list (probably using delegation to hand off the responsibility of what happens each time a "node" is visited, that way you can make a generic 'walk-the-list' method that you set up with a delegate that takes the appropriate action on each node; say, marking it's turn as finished, or whatever.)
  If you try to do both, you're just going to get in trouble.

On Jul 27, 2008, at 1:33 AM, Mark Teagarden wrote:

Hi,

I'm working on a strategy game in which a NSMutableArray called 'army' contains a series of Unit objects. Each Unit contains a property called next_unit, which is a pointer to the next unit in the array - I'm implementing a linked-list so that units can be moved sequentially.

Army starts off with six units, which are assigned one at a time to the array:

for(i=0;i<6;i++){
        u = [[Unit alloc] initWithPositionX:24+i Y:14-i];
        [army addObject:u];
        ...
        [u release];
}

Obviously when the first unit is added, there's nothing for next_unit to point to, so I have to go back and do it on the next loop iteration, which is where my problem arises:

        if(i > 0) [army objectAtIndex:i-1].next_unit = [army lastObject];

Clearly, what I want to do is get the next-to-last unit in army and point its next_unit pointer to the most recently added unit. However, XCode she don't-a like this:

error: request for member 'next_unit' in something not a structure or union

Is there a recommended way for accessing an ivar with synthesized gettors/settors, that belongs to a returned object?

I hope I've explained my problem clearly enough. Thanks for an advice you may offer.

Mark


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/wsquires% 40satx.rr.com

This email sent to [EMAIL PROTECTED]

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to