What I'm looking to do is have a timer that counts down to zero every time a level begins, but I want the starting number to vary each time the level is played. Is there an example of this somewhere?
Develop games in your browser. Powerful, performant & highly capable.
Here you go.
Create a global variable "Random Timer"
Create 3 separate Events
Condition: On Layout start
Action: Set variable Random Timer to "round(random(a,b))" where A is your min number and B is your max number. This will select a number between the two.
Condition: Every 1 Second
Action: Subtract 1 from Random Timer
Condition: Variable Random Timer <= 0
Action: Do what you want here..
Edit: Added Round Expression. Thank you for pointing that out RamPackWobble
Badmiracle - If you change your last event from Variable Random Timer = 0 to Variable Random Timer <= 0 then it should work .
As you have it the timer will be a floating number and might never = 0 (it might be 0.4 then -0.6 for example)
or you could round the random to the nearest whole number.
There are other ways to do this.
here is another method.
Condition: Every tick
Action: Subtract dt from Random Timer
to be more accurate.
For the random number it is better to use "floor(random(b+1))" (or "choose" function if you don't have many numbers to choose from) instead of "round(random(a,b))".
round(random(a,b)) does not generate numbers equally, border numbers (a and b) have 50% less chances to be generated than the numbers between "a" and "b".
EDIT: it should actually be "floor(random(b-a+1)) + a" if you want a range between f.ex. 5 and 10. What I've mentioned before is for ranges starting from 0, like 0 to 10.