Add a value to actors in loop

Game Editor comments and discussion.

Add a value to actors in loop

Postby akhad » Tue Jun 12, 2007 3:50 pm

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;
}
User avatar
akhad
 
Posts: 43
Joined: Tue Jan 16, 2007 1:59 pm
Location: U.K
Score: 0 Give a positive score

Postby Sgt. Sparky » Tue Jun 12, 2007 5:17 pm

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.)
Image
Random Links:
viewtopic.php?p=19474#19474
Right now (10/14/2009) I'm working on some C++ projects, but I might be able to help if you have some Game Editor questions. :)
User avatar
Sgt. Sparky
 
Posts: 1850
Joined: Sat Oct 07, 2006 5:28 pm
Location: Somewhere out there, beneath the pale blue sky...
Score: 236 Give a positive score


Return to GE - General

Who is online

Users browsing this forum: No registered users and 1 guest

cron