Create Random Objects

For questions about using Classic.

Post » Sun Mar 27, 2011 2:25 pm

Hi,

I'm making a top down shooter, and i've created this object to act as a box of items. When clicked the box will open to reveal a random powerup.

I currently have two.

Question is: how do I get it to be random(either powerup a, or powerup b)??

Thanks a million!!
B
4
G
1
Posts: 33
Reputation: 564

Post » Sun Mar 27, 2011 2:29 pm

A 50/50 chance would be random(1), where the out come would be either 0, or 1.
So if random(1) equals 0 do this,
and random(1) equals 1 do that.
Note each time you do a comparison using random it will generate a new number. If you want to choose from one "roll" you will need to save the out put to a variable first, and then compare the variable is = 1, or 0.
Image Image
B
161
S
48
G
90
Posts: 7,356
Reputation: 66,767

Post » Sun Mar 27, 2011 2:34 pm

[quote="newt":24jumi9s]A 50/50 chance would be random(1), where the out come would be either 0, or 1.
So if random(1) equals 0 do this,
and random(1) equals 1 do that.
Note each time you do a comparison using random it will generate a new number. If you want to choose from one "roll" you will need to save the out put to a variable first, and then compare the variable is = 1, or 0.[/quote:24jumi9s]
Random(1) always equals 0. Random(2) would would equal either 0 or 1.
Moderator
B
98
S
37
G
19
Posts: 1,584
Reputation: 17,817

Post » Sun Mar 27, 2011 2:46 pm

um, where do i find random?! i mean, is it in system?! or......?!
B
4
G
1
Posts: 33
Reputation: 564

Post » Sun Mar 27, 2011 2:52 pm

Oops.
Ehhh zero based can be confusing, course not as much as 1 based.
Perhaps I was confusing random(0) for random(1)... oh wait.

[quote="yodason45":3lcw2meq]um, where do i find random?! i mean, is it in system?! or......?![/quote:3lcw2meq]

Its under the system>math>generate random number.
Image Image
B
161
S
48
G
90
Posts: 7,356
Reputation: 66,767

Post » Sun Mar 27, 2011 2:54 pm

It's an expression found in the system object. You use it to set values like this.
Moderator
B
98
S
37
G
19
Posts: 1,584
Reputation: 17,817

Post » Sun Mar 27, 2011 2:55 pm

oh, dang, i don't have math in my system. i forgot to mention, I'm using a older version of Construct. The new one doesn't work properly!!

EDIT: nevermind, i figured out another way!! :P :D
B
4
G
1
Posts: 33
Reputation: 564


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 4 guests