# Timer not working?

Get help using Construct 2

### » Mon May 06, 2013 7:22 am

I'm not really sure what the problem is with my code but it seems like there might be something wrong with the timer.

The problem is that they only seem to pick the first option. It never actually randomizes. I set it to jump and they only jump and if I set it to move right they only move right.

What I want them to do is switch between the 4 behaviors every 2 seconds while Holding is true. Maybe I don't understand how "every x seconds" works but it seems to just be setting them all to the same thing and not doing anything every second.
B
10
S
3
G
3
Posts: 234
Reputation: 3,467

### » Mon May 06, 2013 9:09 am

Random doesn't produce whole numbers, so you need to round it off somehow. I suggest you use floor(random(4)).

Heh, "the random issue" has come up so often lately.
B
57
S
15
G
10
Posts: 912
Reputation: 12,011

### » Mon May 06, 2013 9:12 am

round(random(0,3))
B
18
S
6
G
3
Posts: 197
Reputation: 4,129

### » Mon May 06, 2013 9:46 am

@yonda
Actually I think round(random(0,3)) is wrong

random(0,3) will give you numbers from 0 to almost 3
so you'll get this repartition:[code]
0----------1----------2----------[/code]

if your round that you'll get
[code]0-----|-----1-----|-----2-----|-----
to 0 |   to 1    |    to 2   | to 3    [/code]
So the rounding will introduce a bias toward 1 and 2 and reduce the chance to get 0 or 3.

floor(random(4)), on the other hand, works because you get this:
[code]0----------|1----------|2----------|3----------
to 0   |    to 1   |    to 2   |    to 3[/code]

Hope that makes sense (:Yann2013-05-06 09:47:28
B
61
S
22
G
14
Posts: 1,480
Reputation: 16,373

### » Mon May 06, 2013 10:03 am

Oh my...I'm surprised I forgot about that. Thank you guys.
And thanks a lot Yann for that tip.
B
10
S
3
G
3
Posts: 234
Reputation: 3,467