# Create Random Objects

### » 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
S
1
G
1
Posts: 33
Reputation: 714

### » 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.
B
178
S
50
G
206
Posts: 8,685
Reputation: 127,713

### » 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
115
S
41
G
20
Posts: 1,586
Reputation: 19,196

### » Sun Mar 27, 2011 2:46 pm

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

### » 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.
B
178
S
50
G
206
Posts: 8,685
Reputation: 127,713

### » 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
115
S
41
G
20
Posts: 1,586
Reputation: 19,196

### » 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!!
B
4
S
1
G
1
Posts: 33
Reputation: 714