Page 1 of 1

Create random amount of actors at random points in time

PostPosted: Tue Dec 07, 2010 2:15 pm
by peedalein
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)

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++;
                        }
;

Re: Create random amount of actors at random points in time

PostPosted: Tue Dec 07, 2010 3:38 pm
by schnellboot
could you upload the files please?

Re: Create random amount of actors at random points in time

PostPosted: Tue Dec 07, 2010 4:28 pm
by peedalein
I added the file. Hopefully it works.

Flugzeug => Airplane

BTW is there a way to rename actors other than deleting and creating a new actor?

Thanks for your help.

Re: Create random amount of actors at random points in time

PostPosted: Wed Dec 08, 2010 1:54 pm
by MrJolteon
peedalein wrote:BTW is there a way to rename actors other than deleting and creating a new actor?

No.

Re: Create random amount of actors at random points in time

PostPosted: Wed Dec 08, 2010 11:14 pm
by Toasterman
first off- pretty clever coding on everything
i think the problem is that it is only checking to see if the fcount == the array[i] while i < than arraycount (which is six or so, right?)
that is to say, it is only looking to see if it matches in about the first 5 or 6 frames - I found a way around this (uploaded) but it really isn't half as efficient or cool as the set up you had going- it does seem to work though

-also, when trying to figure out what the problem was, i added a few vars and an actor to report them, as well as modified a few numbers- they aren't important, i was trying to figure out what was going wrong

so is this the effect you were trying to achieve?

Re: Create random amount of actors at random points in time

PostPosted: Fri Dec 10, 2010 10:21 am
by peedalein
Hi!

Thanks for your help. Unfortunately, I couldn't open the file "-> couldn't open data\msyh.ttf"

Re: Create random amount of actors at random points in time

PostPosted: Fri Dec 10, 2010 10:27 am
by skydereign
To get around this, just create a data folder where the ged is, and then copy a different .ttf file into it, and rename the file. That way it "has" the font. Anyway, here it is.

Re: Create random amount of actors at random points in time

PostPosted: Fri Dec 10, 2010 11:15 am
by peedalein
Hi!

That code works very nicely. Thank you!

One quick question. What is the purpose of "j"? Seems that it is always set 0.

EDIT: Scrolled to the right side of the code..got what j does.

Re: Create random amount of actors at random points in time

PostPosted: Sun Dec 12, 2010 3:24 am
by Toasterman
Glad my code helped :D

only creates a supply if j < Arraycount-
j++ after each "create supply", then after running through that 5 or 6 times (whatever the max number of Arraycount is) it is reset at 0

This may not be the most efficient or devilishly clever way to get it done, but it seems to work and that was the best my slightly sleep deprived brain could think of at the time :lol:

one problem i noticed is that the computer finds 3 or 5 or however many places to put a supply, but they are often on top of each other- I'm not sure how to fix this perfectly, maybe have them destroy each other if they touch, or make a smaller icon, or have a physical response or something- it's not really a big deal though, just a thought