How do I Use Random and Wait Together?

0 favourites
  • 8 posts
From the Asset Store
Easily generate many levels from a set of pre-built scenes (Construct 3 template)
  • 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.

    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.

  • double

  • 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.

  • 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!

  • 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.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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

  • didnt fully grasp what you were trying to do, my apologies. Simply get rid of the instance variable. Put The RANDOM(Min,MAX) Wait.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)