How I Use Alarm System

N

NoobInside12

Guest
Hello! Im new using Game Maker so I do not know many things but I'm having more problems and how to use the alarm system someone could help me how to use? thank you ;)
 

NazGhuL

NazTaiL
TO trigger something after a certain time.
I.E, you want to trigger variable A from false to true after 5 seconds:

Code:
//Create event:

A = false;
alarm[0] = 5*room_speedl

//Alarm[0] event:
A = true;
==edit==
if you want something repetitive:
Code:
//Create event:
Rnd_Number = irandom_range(1,100):
alarm[0] = 5*room_speed;

//Alarm[0] event:
Rnd_Number = irandom_range(1,100):
alarm[0] = 5*room_speed;
Every 5 seconds Rnd_Number will change becasue alarm[0] reset itself, like a loop.
 
S

Snail Man

Guest
To elaborate a bit, you have to remember that the alarms are measured in steps or frames, so setting an alarm to 5 will only be five frames which is one sixth of a second by default! To correct for this, you need to multiply by the frames per second, which is stored in a variable called "room_speed", to get the number of seconds. NazGhul's code would set an alarm after 5 seconds for example. After the time on the alarm is up, it will trigger the alarm event of the corresponding number, so if you set alarm 0, the alarm 0 event will occur 5 seconds later.

Hope this helps!
 
N

NoobInside12

Guest
TO trigger something after a certain time.
I.E, you want to trigger variable A from false to true after 5 seconds:

Code:
//Create event:

A = false;
alarm[0] = 5*room_speedl

//Alarm[0] event:
A = true;
==edit==
if you want something repetitive:
Code:
//Create event:
Rnd_Number = irandom_range(1,100):
alarm[0] = 5*room_speed;

//Alarm[0] event:
Rnd_Number = irandom_range(1,100):
alarm[0] = 5*room_speed;
Every 5 seconds Rnd_Number will change becasue alarm[0] reset itself, like a loop.
then how could I create an object with the first example? removing the "A" and putting the object name?
 
N

NoobInside12

Guest
TO trigger something after a certain time.
I.E, you want to trigger variable A from false to true after 5 seconds:

Code:
//Create event:

A = false;
alarm[0] = 5*room_speedl

//Alarm[0] event:
A = true;
==edit==
if you want something repetitive:
Code:
//Create event:
Rnd_Number = irandom_range(1,100):
alarm[0] = 5*room_speed;

//Alarm[0] event:
Rnd_Number = irandom_range(1,100):
alarm[0] = 5*room_speed;
Every 5 seconds Rnd_Number will change becasue alarm[0] reset itself, like a loop.

to create something repetitive I put both on the same object and instead of "Rnd_number" I put "instance_create (x, y, object)" right?
 
X

Xskode

Guest
Hello! Im new using Game Maker so I do not know many things but I'm having more problems and how to use the alarm system someone could help me how to use? thank you ;)
The alarm system is use to activate (begin) a program (set/lines) of code(s) when that alarm = 0.
What I do is inside a create event (on the object that will use the alarm), I set the alarm by doing the following:

CREATE EVENT:
alarm[0] = room_speed * 1; ///What that does is make the - alarm[0] - active in one second. if you wanted 5 seconds change the 1 to 5. etc...

once the alarm is set, you will need to add the exact alarm as an event by doing the following:
Click Add Event (on the same object), click - alarm - then select the correct alarm. In this example it would be - alarm[0] -

now whatever code you put inside this alarm event will happen when alarm[0] = 0.

HOW ALARMS WORKS:
once you set an alarm gamemaker will begin subtracting 1 from the value you assigned to that alarm every step.

WHAT ARE STEPS:
when you create a room go into the room's setting tab. there you will see a section named - Speed -
whatever value you put here will indicate- how many steps are in a second. So lets put 60 into that section. Now your game will run 60 frames per second / 60 steps per second.

LETS FULLY UNDERSTAND ALARMS:
So now we can look at the code we did earlier, and understand exactly how it works.
The code { alarm[0] = room_speed * 1 } is equal to one second. how? well, since the room_speed = 60 and 1 is subtracted every step, and since the room_speed is also the total number of steps in a second,
gamemaker will subtract 1 every step- meaning 60times which takes 1 second. And remember, the number we times the room_speed by is the total number of seconds we want.

QUIZ TIME:
how many seconds are the following(s) ?
  1. alarm[0] = room_speed * 4; = how many seconds >>>
  2. alarm[0] = room_speed * 3; = how many seconds >>>
  3. alarm[0] = room_speed * 37; = how many seconds >>>


I saw your post and you mention you're new using GameMaker, So I took alittle more time to teach instead of show. hopefully that helped you out with understand/using alarms.
and if you still have question(s), just post. there are many knowledgeable members that can help you out with problems you might come across during your programming.
 

Yal

🐧 *penguin noises*
GMC Elder
to create something repetitive I put both on the same object and instead of "Rnd_number" I put "instance_create (x, y, object)" right?
Correct :3

It's worth keeping in mind that alarms are local, e.g. all objects has their own 12 alarms, so you don't need to worry about having to use different alarms for all objects.
 
Top