Question: What is an alarm in GameMaker?


Alarms in GameMaker are essentially countdown timers that can be set to trigger an event after a specified number of steps (with each step typically corresponding to one frame). In GameMaker, there are 12 alarms available for each instance, named alarm[0] through alarm[11].

To use an alarm, you will assign it a value (the number of steps to count down) and when this value counts down to zero, the Alarm Event for the corresponding alarm number will be triggered. Within this Alarm Event, you can place code to perform any action you wish, such as creating objects, changing variables, or controlling game states.

Here's an example of how to set an alarm:

// Set alarm[0] to go off in 2 seconds (assuming room_speed is 60) alarm[0] = 2 * room_speed;

And here's what you might do when the alarm goes off:

/// Alarm 0 Event instance_create_layer(x, y, "Instances", obj_Explosion);

This would create an explosion object at the current position of the instance after 2 seconds have passed.

Alarms only count down when the instance that set them is active, and they do not continue counting down if the instance is destroyed or deactivated.

Using alarms is a fundamental aspect of timing in GameMaker games, making them crucial for gameplay programming, spawning events, cooldowns, delays, and more complex game mechanics.

Was this content helpful?

White Paper

Free System Design on AWS E-Book

Download this early release of O'Reilly's latest cloud infrastructure e-book: System Design on AWS.

Free System Design on AWS E-Book

Start building today

Dragonfly is fully compatible with the Redis ecosystem and requires no code changes to implement.