Random clone

Non-platform specific questions.

Random clone

Postby Troodon » Mon Feb 26, 2007 2:44 pm

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.
I can't die, I already tried
~on the forums since GE 1.3.3~
User avatar
Troodon
 
Posts: 1539
Joined: Thu Jan 12, 2006 3:29 pm
Location: HELL
Score: 56 Give a positive score

Postby DilloDude » Mon Feb 26, 2007 9:52 pm

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.
Image
User avatar
DilloDude
 
Posts: 866
Joined: Tue Jan 24, 2006 9:51 am
Location: Nyerellion
Score: 58 Give a positive score

Postby Troodon » Tue Feb 27, 2007 4:25 pm

When I type the

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

it says "cast loses const qualifier"
I can't die, I already tried
~on the forums since GE 1.3.3~
User avatar
Troodon
 
Posts: 1539
Joined: Thu Jan 12, 2006 3:29 pm
Location: HELL
Score: 56 Give a positive score

Postby makslane » Tue Feb 27, 2007 4:36 pm

Try this:

Code: Select all
getclone((char*)clonename);
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest