actor arrays, for instance actor.0 actor.1 actor.2 etc.

Talk about making games.

actor arrays, for instance actor.0 actor.1 actor.2 etc.

Postby MrScience101 » Fri Mar 23, 2007 1:16 am

I would like to cycle through actors creating or destroying them based upon an array of 25 actors. I created an array of 25 actors using the array function. I then created a button that when I press it I want to destroy a certain number of them based on their preset values.

For instance when I click on a button labled 'lever 1' A script is called that does the following:

int i;

for(i=0;i<25;i++)
{
if(actornamegoeshere.i.alive == 1)
DestroyActor("actornamegoeshere.i");
}


However only the first actor is ever destroyed. It seems the .i method doesn't work. Any ideas on how to cycle through an array of actors?

Much Thanks.
MrScience101
User avatar
MrScience101
 
Posts: 115
Joined: Tue Mar 20, 2007 9:52 pm
Score: 13 Give a positive score

Postby makslane » Fri Mar 23, 2007 1:22 am

makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

Postby MrScience101 » Fri Mar 23, 2007 1:46 am



That's a cool thread thankyou. Here is the code I use:

int i;

DestroyActor("BlueLight");

for(i=0;i<10;i++)
{
DestroyActor(getclone2("PurpleLight",i));

}

unfortunately it generates a warning and then does not destroy anything when executed. :(
User avatar
MrScience101
 
Posts: 115
Joined: Tue Mar 20, 2007 9:52 pm
Score: 13 Give a positive score

Postby makslane » Fri Mar 23, 2007 2:01 am

The getclone and getclone2 function returns a pointer to the actor.
In your case, use the sprintf function to format the string:

Code: Select all
char name[64];
for(i=0;i<10;i++)
{
 sprintf(name, "PurpleLight.%ld", i);
 DestroyActor(name);
}
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

Postby MrScience101 » Fri Mar 23, 2007 2:42 am

makslane wrote:The getclone and getclone2 function returns a pointer to the actor.
In your case, use the sprintf function to format the string:

Code: Select all
char name[64];
for(i=0;i<10;i++)
{
 sprintf(name, "PurpleLight.%ld", i);
 DestroyActor(name);
}


Wow, I am used to waiting weeks for an answer. The above code worked wonderfully, thank you. I guess I need to learn a little more c. :D
User avatar
MrScience101
 
Posts: 115
Joined: Tue Mar 20, 2007 9:52 pm
Score: 13 Give a positive score


Return to Game Development

Who is online

Users browsing this forum: No registered users and 1 guest