Create random amount of actors at random points in time

Game Editor comments and discussion.

Create random amount of actors at random points in time

Postby peedalein » 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)

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++;
                        }
;
peedalein
 
Posts: 54
Joined: Mon May 17, 2010 2:26 pm
Score: 1 Give a positive score

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

Postby schnellboot » Tue Dec 07, 2010 3:38 pm

could you upload the files please?
schnellboot
 
Posts: 819
Joined: Sat Mar 31, 2007 1:35 pm
Location: Germany
Score: 102 Give a positive score

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

Postby peedalein » Tue Dec 07, 2010 4:28 pm

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.
Attachments
airplane.zip
(8.43 KiB) Downloaded 75 times
peedalein
 
Posts: 54
Joined: Mon May 17, 2010 2:26 pm
Score: 1 Give a positive score

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

Postby MrJolteon » Wed Dec 08, 2010 1:54 pm

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

No.
Join us on Discord!
Game Editor 2
These are the best ways to reach me these days


Your local Community Janitor, always lurking in the shadows...
User avatar
MrJolteon
 
Posts: 2326
Joined: Sat Aug 09, 2008 3:25 pm
Location: Stranded under endless sky
Score: 105 Give a positive score

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

Postby Toasterman » Wed Dec 08, 2010 11:14 pm

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?
Attachments
fixed...maybe.ged
(4.34 KiB) Downloaded 68 times
"If there are no stupid questions, what kind of questions do stupid people ask? Do they get smart just in time to ask a question? -Scott Adams

Hey! I've got okayish internet now! Now I can try all those cool demos I've seen!
User avatar
Toasterman
 
Posts: 75
Joined: Thu Jul 22, 2010 4:22 am
Location: Drowning in Dial-Up Ocean
Score: 7 Give a positive score

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

Postby peedalein » Fri Dec 10, 2010 10:21 am

Hi!

Thanks for your help. Unfortunately, I couldn't open the file "-> couldn't open data\msyh.ttf"
peedalein
 
Posts: 54
Joined: Mon May 17, 2010 2:26 pm
Score: 1 Give a positive score

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

Postby skydereign » Fri Dec 10, 2010 10:27 am

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.
Attachments
fixed...maybe.zip
(20.36 KiB) Downloaded 67 times
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

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

Postby peedalein » Fri Dec 10, 2010 11:15 am

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.
peedalein
 
Posts: 54
Joined: Mon May 17, 2010 2:26 pm
Score: 1 Give a positive score

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

Postby Toasterman » Sun Dec 12, 2010 3:24 am

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
"If there are no stupid questions, what kind of questions do stupid people ask? Do they get smart just in time to ask a question? -Scott Adams

Hey! I've got okayish internet now! Now I can try all those cool demos I've seen!
User avatar
Toasterman
 
Posts: 75
Joined: Thu Jul 22, 2010 4:22 am
Location: Drowning in Dial-Up Ocean
Score: 7 Give a positive score


Return to GE - General

Who is online

Users browsing this forum: No registered users and 1 guest