I need to rebuild my timer as it is not only slightly inaccurate, but I have no way of controlling it.
Basically, I have a custom event “LevelTimer” I set 2 variables for min and sec, decrement sec manually after a 1sec Delay, when both reach 0 → end the level.
The problem is that if the level is ended sooner,(for other reasons) I pause the game do some stuff in the EndLevel widget and when I stream the next level and unpause the game the original event continues to run from where it left off. Even if I reset the original min and sec variables.
I would like to build a more complex timer (based on world delta seconds) by using Set Timer by Event, be able to pause it and reset it on demand and constantly update a single variable for sec (float with 2 decimals).
I’ve checked countless tutorials on YT but none show how to actually control the timer, by stopping/resetting it on demand.
As always, any pointers are greatly appreciated
If you put the timer in the game instance, it can exist in between levels if you want, but also, you can always use it without having to put the code in each level.
When you start a timer by event, you get a reference to the timer, which you can use to stop it and restart it.
Well, I have it in my GM and apparently, somehow, it still persists through streaming levels somehow.
Imagine this…
user completes Level1 → I pause the game → display EndLevel widget.
Play with some math inside the widget, if user clicks “Continue” → I load the next streaming level
When the new level loads → I reset the min and sec variables in GM → call the LevelTimer custom event from GM again and when that comes up, for a split second it shows the reset variables, but after that it continues from where it left off in the previous level.
Nonetheless, just by looking at your example I realized I can link my LevelTimer event to another event and by using set timer by event I can actually get the reference to my timer which opens up a whole new set of controls.
Thank you so much!
I still left the timer in my GM bp but when the level ends I no longer need to pause the game.
I just disable the input for the player → Pause the timer ->load the EndLevel widget
Do my math in there → when the user clicks “Continue” → Clear the old timer → load the new level → call the StartTimer event and it works perfectly.
I would still like to rebuild my timer function to use only seconds and milliseconds since I don’t really need minutes.
I don’t have a clue about using the delta seconds to count down from 60 using only seconds and milliseconds up to 2-3 decimals.
Anyways, @ClockworkOcean your answer got me in the right direction. Much appreciated good sir!
@ClockworkOcean
The only reason I would like to go with sec and milliseconds is that I want to use that number as a bonus multiplier.
Each target has a specific # of points associated with it.
Let’s say you have 10 targets in Level1.
2 players complete the level.
The way I want to differentiate which one is the winner is by multiplying the total points lets say 10targets * 10 points each = 100 points * (the time remainder for the level). The milliseconds could make the difference here.
Isn’t World Delta Seconds supposed to be super accurate independent of the user’s fps???
I just have no clue how to build a countdown timer using delta
This works, but I just realized I don’t ever need the minutes. I could however make use of the milliseconds… just no clue how to get that and incorporate it in my code.
Instead of 1:00 the timer could start at 60.00 seconds were .00 is the countdown for milliseconds
However, of course I pushed myself into another corner now…
How can I add my beeping sound for the last 10 sec? 10,9,8…0 (and not the decimals in between)??
Why when comparing floats it was not working??? if 10.00 = 10.0 was not triggering the sound… but when ceiling it to an int and comparing to 10 it does???
Same thing for when the timer reached 0. If 0.00 = 0.0 was not changing the bool??? Why???
Comparing floats can be tricky because of precision errors. Notice I used TimeLeft < 0.0 and not ==.
Also keep in mind that between each timer loop it will not be exactly the value of the interval variable. It will always by greater by a few miliseconds. So don’t exepct it to run every 0.1 seconds, reality will be 0.1 + ms fraction to next frame.