script help?

Posted by Z-Gamers on Aug. 25, 2008, 10:01 p.m.

Quote: code
r1=random(10)

r2=random(10)

r3=random(10)

r4=random(10)

r5=random(10)

if r1=5

{instance_create(x,y,obj_m_enemy1)}

if r2=5

{instance_create(x+112,y,obj_m_enemy1)}

if r3=5

{instance_create(x+240,y,obj_m_enemy1)}

if r4=5

{instance_create(x+384,y,obj_m_enemy1)}

if r5=5

{instance_create(x+560,y,obj_m_enemy1)}

Doesn't work, please help.

Comments

Siert 17 years ago

When you use random() it generates a random number including decimals.

ie. 3.20847294862

The simplest way to fix this is to add round() to your code.

ie. r1=round(random(10))

NeutralReiddHotel 17 years ago

Well, Siret beat me to it. It's not like I explained it right anyway. Also, SHORT BLAWG.

SteveKB 17 years ago

lol I remember learning how to do that a few weeks ago, but by my self, I was thinking how do I duplicate the dice roll event in code and then I remembered the decimals in random functions and rounded. You should browse more through the functions of the help file, search round in the help file index and it will come to a page with many functions with terrible descriptions.

F1ak3r 17 years ago

According to NakedPaulToast, it's better to use floor instead of round.

WaleedAmer 17 years ago

Another function you might wanna know:

choose(x1,x2,x3,…)

It chooses one of the arguments randomly.

F1ak3r 17 years ago

choose is a brilliant function. I use it all the time.

SquareWheel 17 years ago

Shoot, I wrote out the full code and explanation before realizing there was already comments.

And had to post this to make myself feel better.

melee-master 17 years ago

The issue is resolved and thus this does not need to be on the front page any longer.

Taken off.