Page 1 of 1

Random clone

PostPosted: Mon Feb 26, 2007 2:44 pm
by Troodon
Hi,
It's me again. I know I'm asking too many questions and here is one again. (Maybe I should make a topic called "Tekdino's questions")

Is there any way to read a random clone in GE?
I need it to make a random moveto target clone.

PostPosted: Mon Feb 26, 2007 9:52 pm
by DilloDude
The easiest way would be to store the clones in an array. You could just use a random based on ActorCount, but some clones might not exist, so I suggest the array method. You will need an integer called 'count' (or rockCount or enemyCount or whatever, if you want to have more for other things.) In global code you can make the array:
Code: Select all
Actor *actorArray[500];
(or rockArray or enemyArray). Change the 500 to the maximum number of actors you want to have at once. You also need an actor variable called 'number' (or index or something) so each ator knows where it is in the array. On each actor's create actor event, you need to update array and count:
Code: Select all
array[count] = getclone(clonename);
number = count;
count ++;

You nedd to add a destroy actor event, to remove the actor from the array:
Code: Select all
count --;
array[number] = array[count];

When you select a random actor, you can use this code:
Code: Select all
int acnum = round(rand(count - .00001) - .5);
//if you need the actor as a target, get its clonename:
array[acnum]->clonename
//if you need the actor's location:
array[acnum]->x, array[acnum]->y


Note: befor you create another actor, you need to check if count is < 500) or whatever the size of the array is:
Code: Select all
if (count < 500)
{
    CreateActor...
}


Hope that helps.

PostPosted: Tue Feb 27, 2007 4:25 pm
by Troodon
When I type the

array[count] = getclone(clonename);
number = count;
count ++;

it says "cast loses const qualifier"

PostPosted: Tue Feb 27, 2007 4:36 pm
by makslane
Try this:

Code: Select all
getclone((char*)clonename);