Create random amount of actors at random points in time
Posted: Tue Dec 07, 2010 2:15 pm
Hi everybody!
Currently I am working on a game where an airplane drops supplies, the player has to collect these supplies.
The airplane is moving from the right to the left or vice versa depending on a random generated variable.
The airplanes movements are triggered by coordinates and frames. I use the fcount method to count the frames (actor variable fcount, in Draw Actor fcount = fcount + 1)
I would like the airplane to drop a random generated number of supplies in random points of time.
For the random generated numbers I use the following in Global Script(found it in the forum)
This code is in Airplane DRAW Actor
This allows me to create a random amount of random numbers at the beginning of each cycle (fcount == 0). The random numbers are the frames when the airplane is supposed to drop the supplies. This part works. Example: Arraycount = 4; Frame = 33, 37, 39, 48
How do I tell my airplane to drop off the supplies resp. create the supply actor at a random number of randomly
generated frames?
I used the code below but that it does not work.
Currently I am working on a game where an airplane drops supplies, the player has to collect these supplies.
The airplane is moving from the right to the left or vice versa depending on a random generated variable.
The airplanes movements are triggered by coordinates and frames. I use the fcount method to count the frames (actor variable fcount, in Draw Actor fcount = fcount + 1)
I would like the airplane to drop a random generated number of supplies in random points of time.
For the random generated numbers I use the following in Global Script(found it in the forum)
- Code: Select all
int RandomBetween(int a,int b)
{
int random=rand(max(a,b)-min(a,b));
int start=min(a,b);
return start+random;
}
This code is in Airplane DRAW Actor
- Code: Select all
// to create a random amount for the Array
if (fcount == 0) {Arraycount = RandomBetween(3,6)};
// to create random numbers (frames)
if (fcount == 1) {while (i < Arraycount)
{Array[i] = RandomBetween(30,60);
i++;}}
This allows me to create a random amount of random numbers at the beginning of each cycle (fcount == 0). The random numbers are the frames when the airplane is supposed to drop the supplies. This part works. Example: Arraycount = 4; Frame = 33, 37, 39, 48
How do I tell my airplane to drop off the supplies resp. create the supply actor at a random number of randomly
generated frames?
I used the code below but that it does not work.
- Code: Select all
while (i < Arraycount) {
if (fcount == Array1[i]) {CreateActor("Supply", "icon", "(none)", "(none)", 0, 0, false);}
;
i++;
}