How do I Use Random and Wait Together?

Get help using Construct 2

Post » Wed May 17, 2017 8:17 pm

I can't seem to figure out if I'm doing something wrong with the random function or if this is one of those instances where I should be using a timer instead of wait.
Image

Essentially, what happens is that no matter what values i put in my range - it always just uses the first one. So if it's (8,25) it saves 8. If I put (15,25) it puts 15. If I do (25,250) it waits 25 seconds.

I seem to have the same problem if I try and do it with a global variable so I can't help but think it's an issue with random or using the wait function.
B
8
S
1
G
1
Posts: 8
Reputation: 441

Post » Wed May 17, 2017 8:43 pm

double
Last edited by 99Instances2Go on Wed May 17, 2017 8:54 pm, edited 1 time in total.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Wed May 17, 2017 8:43 pm

Depends.

I see that you dont change the value of Game_Started. You should have done that in this event.

Since i do not see (and have to guess) your other events, i assume that you forgot to change its value or have some timer on it.

As a result this event runs several ticks, presumably FPS times * first value in range . If you create those random numbers fast enough and for enough time, the first value for sure gets chosen. That value happens to be the shortest time. So when DRAW pops into existence it is at that shortest wait time, or the first one in the range. The other (FPS times * first value in range) wait calls you dont see happen.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Wed May 17, 2017 10:30 pm

Thanks for that. I had a different event that changed the value of Game_Started to 0. I tried doing a "stop loop" and that didn't seem to do the trick. Then I changed the value of Game_Started to 0 within the same even as you suggested but as the last item on the list and ended up having the same issue. So, I then made the value change be the first step of that event and it seems to have cleared it up.

Just so i understand, why would it matter where the value of Game_Started is changed if it's within the same event?

Thanks again!
B
8
S
1
G
1
Posts: 8
Reputation: 441

Post » Thu May 18, 2017 8:02 am

Lanhoj wrote:Just so i understand, why would it matter where the value of Game_Started is changed if it's within the same event?


Events run every tick, Wait does not stop that, it just delays the actions after the Wait.

Changing the value at the start prevents the Event running in the next tick.

Changing the value at the end allows the Event to be repeated for however many ticks fit into your wait time.
Find all the Construct 2 games that were on Steam Greenlight here
B
33
S
9
G
7
Posts: 451
Reputation: 6,782

Post » Thu May 18, 2017 8:27 am

so, wait is an action not an event, in system you should see every X seconds as an event. you should be able to set it up as an additional condition to Game = 1. that way, If Game =1, Every Random (x,Y) Seconds, Action Will Happen
B
22
S
12
G
1
Posts: 108
Reputation: 2,774

Post » Thu May 18, 2017 8:38 am

didnt fully grasp what you were trying to do, my apologies. Simply get rid of the instance variable. Put The RANDOM(Min,MAX) @ Wait.
B
22
S
12
G
1
Posts: 108
Reputation: 2,774



Return to How do I....?

Who is online

Users browsing this forum: No registered users and 25 guests