A simple question - is it possible to run a while loop over a subset of characters named cChar1, cChar2 etc. that do not have consecutive id numbers? Or am I stuck with using a custom property or similar and having to check against that whilst iterating over the whole set?
Thanks
Well, you could set up an array of the character ID's used by cChar1, cChar2 and so on, and then iterate through that.
Thus instead of doing:
int n;
while (n < 10) {
character[n].DoStuff();
n++;
}
etc.
You would declare:
int mydudes[10];
globally, and then in game_start you could define:
mydudes[0] = cChar1.ID; //or just the plain number, you get the point
mydudes[1] = cChar2.ID;
mydudes[2] = cChar3.ID;
//...
mydudes[9] = cChar10.ID;
then in the function, do this:
int n;
while (n < 10) {
character[mydudes[n]].DoStuff();
n++;
}
Make a custom property called "next", then rather than doing "n++" in your loop, do this:
int n = SOME_CHARACTER
while (n != 0) {
do stuff
n = character[n].next;
}
Ooooh I like that linked list approach. Thanks a bunch.