Page 1 of 1

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

PostPosted: Fri Mar 23, 2007 1:16 am
by MrScience101
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

PostPosted: Fri Mar 23, 2007 1:22 am
by makslane

PostPosted: Fri Mar 23, 2007 1:46 am
by MrScience101


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. :(

PostPosted: Fri Mar 23, 2007 2:01 am
by makslane
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);
}

PostPosted: Fri Mar 23, 2007 2:42 am
by MrScience101
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