Page 1 of 1

Add a value to actors in loop

PostPosted: Tue Jun 12, 2007 3:50 pm
by akhad
I'm converting some old Basic code I made a while back. When it comes to the For/Next loops I'm not sure how they translate to GE. For example, to assign the value 100 to the X position of 5 objects in my old code is something like:

for a=1 to 5 : Position Object (a),100,0 : Next a

How can I do a similar thing to my actors, ie if they are named as
Alien1, Alien2, Alien3 etc....
Can I do a For/Next loop and assign values to an array of 5 objects called Alien with something like...

for(i=0; i<5; i++)
{
Alien[i].x=100;
}

PostPosted: Tue Jun 12, 2007 5:17 pm
by Sgt. Sparky
make a variable called NAME and make it a global string and use the code,
Code: Select all
int i = 0;
for(i = 0; i <= 5; i++)
{
    sprintf(NAME, "Alien.%d", i);
    getclone(NAME)->x = 100;
}

:D
(I use code like this all the time for saving stuff and positioning.)