Alarms

Alarm

Alarm Guide

Alarms are useful for when you want to count down, for example, to create a countdown timer, time limit, waiting time, or delay. An alarm can also useful for putting spaces between shots in a bullet stream. Every object in Game Maker has 12 alarms built in.

How Alarms Work

When an alarm is set, it begins to count down. When the count reaches 0, the Alarm event for that alarm goes off. The Alarm event allows you to execute actions in response to the alarm going off. An alarm will not count down unless there is an action in the Alarm event.

Setting an Alarm

When an alarm is set, it begins to count down to . Once it reaches it triggers an Alarm event and sets itself to -1.

Setting an Alarm with GML

The code below will set an alarm to go off in 20 seconds :

alarm[0] = room_speed * 20;

Alarm Array

Alarms are built into objects using an array named alarm[]. The array index has a range from 0 to 11, each one of them representing one of the 12 built-in alarms.

Countdown Timer / Time Limit

A countdown timer is a timer that counts down, creating a time limit. A countdown timer can be made using an alarm. First, set the alarm for the number of seconds you want the time limit to be.

alarm[0] = room_speed * 30;

Once you do this, the count down will begin.

Displaying the Countdown Timer

You can display the time left to the player using draw_text() to show a caption along with the value of alarm[0]. You will have to convert the steps left in the timer to seconds by dividing by the room_speed.

draw_text(10,10,string(floor(alarm[0]/room_speed)));

Finally, any code you want to run when the alarm goes off, put in the Alarm Event associated with alarm[0], which is Alarm 0.