views:

1501

answers:

2

If you want to use an array of characters/badguys is it better to have one array of badguy objects and each object have properties like Badguy1: color=blue, health=80. Then you loop through your array of characters and pull that information.... OR is it better to have multiple small arrays like character array, color array, health array and the index of all 3 arrays align to be the same character?

I know how to pull information from each array if it is separate but I do not know how to get the properties of each character if it is all wrapped up in 1 array.

I ask just because it seems like it would make more sense to use a single array and pull the parts that you need.

A: 

Actually, now that I think about it. I guess I should just have an array of pointers and then get my values from the objects and not try to store all of that in the array.

SonnyBurnette
A: 

I know how to pull information from each array if it is separate but I do not know how to get the properties of each character if it is all wrapped up in 1 array. I ask just because it seems like it would make more sense to use a single array and pull the parts that you need.

You are correct in that it's generally smarter and a better design decision to keep related things together. If you'd like to store them this way, you can simply do:

// Get the character at index 3 in the "characters" array
//   and print how many hit points it has left.
GameCharacter *ch = [characters objectAtIndex:3];
NSLog(@"This character has: %@ hit points", ch.hitPointsRemaining);
John Feminella