• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Can you pause alarms? And can alarms be run accurately using delta_time?

otterZ

Member
1) Can an alarm be paused? As in if there is an alarm set to go off in 120 game steps but gameplay dictates that it should now go off in 130 game steps, is there any way of pausing that alarm for 10 game steps? And would it be possible to pause a group of alarms if you have say 100 alarms set to trigger at different times?

2) Can alarms be linked to delta_time, rather than game steps, to create very accurate timers that are as close to real time as possible?

I am playing around with some ideas to get this done in a test project, but any pointers from more experienced GM programmers would be much appreciated.
 

TsukaYuriko

☄️
Forum Staff
Moderator
1) Can an alarm be paused? As in if there is an alarm set to go off in 120 game steps but gameplay dictates that it should now go off in 130 game steps, is there any way of pausing that alarm for 10 game steps?
Add 10 to the alarm.

And would it be possible to pause a group of alarms if you have say 100 alarms set to trigger at different times?
Add 1 to the alarms every step for as long as they should be paused (unless they are -1).

2) Can alarms be linked to delta_time, rather than game steps, to create very accurate timers that are as close to real time as possible?
The built-in alarms can not. Custom alarms can.
 

otterZ

Member
Thank you TsukaYuriko :)

In experimenting in test projects I've been using this method for more accurate alarm timing today. Seems to work . . .

GML:
target_delta = 1/60;
actual_delta = delta_time/1000000;
delta_multiplier = actual_delta/target_delta;

alarm[0] = delta_multiplier * 60;
alarm[1] = delta_multiplier * 120;
alarm[3] = delta_multiplier * 180;
alarm[4] = delta_multiplier * 240;
There is probably a more elegant way, but if it does the job I'll take that.

Edit: [No it doesn't work lol - after reading tips from more experienced GM coders, as you can read below]
 
Last edited:

sp202

Member
delta_multiplier will change if you have any sort of slowdown, so you'd have to readjust all your alarms. Might be best to simply use your own alarms if you want to be linked to time rather than steps.
 

NightFrost

Member
Delta_time remains constant as long as your game is managing to run at full FPS speed it has been set to. When slowdown occurs it increases, because it is a time counter since previous frame was run. Alarms tick down by one every step, so they do not match the variance delta time gives rest of your game. For example, if your game is set to run at 60fps, but manages to freeze for a full 60 frames (one second), when your delta timed operations react to that they behave as if sixty steps had passed, but GMS will decrement alarms by one because only one frame (step) has passed. In other words, you should write your own counters and decrement / increment them by delta, and check if the counter has reached or is past its target value ( if(counter <= 0) etc).
 

otterZ

Member
Good point, thanks sp202. I will look into how to create my own alarms linked more to real time, I've never done that before so it will be a learning experience.
 

otterZ

Member
Delta_time remains constant as long as your game is managing to run at full FPS speed it has been set to. When slowdown occurs it increases, because it is a time counter since previous frame was run. Alarms tick down by one every step, so they do not match the variance delta time gives rest of your game. For example, if your game is set to run at 60fps, but manages to freeze for a full 60 frames (one second), when your delta timed operations react to that they behave as if sixty steps had passed, but GMS will decrement alarms by one because only one frame (step) has passed. In other words, you should write your own counters and decrement / increment them by delta, and check if the counter has reached or is past its target value ( if(counter <= 0) etc).
That is so helpful NightFrost. Thank you for explaining that. I will create a test project and try writing my own counters after a bit of research and manual reading about this topic. Cheers.
 
Top