# How do I generate random variables on separate objects?

Get help using Construct 2

### » Sun Oct 02, 2016 3:07 pm

I have this

but it doesn't set it to anything but variable "0" for "Type".

If I force a number like 1 or 2. It loads properly in...
B
7
S
1
Posts: 28
Reputation: 483

### » Sun Oct 02, 2016 3:17 pm

I would take the for each EnemyCntrl out of the nested loop and have a separate event, on EnemyCntrl created > set type to random (0,2) but that's just me.
Last edited by plinkie on Sun Oct 02, 2016 3:18 pm, edited 1 time in total.
B
52
S
21
G
93
Posts: 2,418
Reputation: 55,024

### » Sun Oct 02, 2016 3:17 pm

System expressions

random(x)
Generate a random float from 0 to x, not including x. E.g. random(4) can generate 0, 2.5, 3.29293, but not 4. Use floor(random(4)) to generate just the whole numbers 0, 1, 2, 3.
B
67
S
24
G
7
Posts: 1,519
Reputation: 11,104

### » Sun Oct 02, 2016 4:45 pm

For any floating point number: random(2)
If you only want integers floor( random(2) )
B
29
S
10
G
10
Posts: 97
Reputation: 6,614

### » Sun Oct 02, 2016 5:28 pm

Well I did this...

still doesn't seem to work... it doesn't seem to affect the new spawning ones
B
7
S
1
Posts: 28
Reputation: 483

### » Sun Oct 02, 2016 5:36 pm

korbaach wrote:System expressions

random(x)
...Use floor(random(3)) to generate just the whole numbers 0, 1, 2,
B
67
S
24
G
7
Posts: 1,519
Reputation: 11,104

### » Sun Oct 02, 2016 5:44 pm

korbaach wrote:
korbaach wrote:System expressions

random(x)
...Use floor(random(3)) to generate just the whole numbers 0, 1, 2,

Oh "floor" isn't just a random object word? I thought it was an example... uh I'm dumb...

I appreciate everyone putting up with me here.

EDIT:

Seems to be affecting only one area now...

B
7
S
1
Posts: 28
Reputation: 483

Return to How do I....?

### Who is online

Users browsing this forum: burak22, kelany and 4 guests