GameMaker Call an Alarm event on an instance id

H

Heath Close

Guest
I have a drag and drop on an object that is set up to shake it. I want to be able to call it from another object so I put it in an alarm, one that is never used so I figured it would be safe to put it there.

I want to call this alarm event from another object... how do I get this code to work?

Code:
event_perform_object(inst_1EC08766,ev_alarm,0);
 
2

2Create

Guest
It sort of depends on whether you want to call the alarm event in all instances of an object, or only in one specific instance.

Each instance has an id that is assigned it runtime, so if you want to call it in one instance, you will need to find a way to pass that id on to the instances that need to call it. This could for example be done by setting a global variable to that instance's id, and then using that variable to call the alarm event. In code, that would look like this:
In the object that needs its alarm event called (after ascertaining it's the right instance)
Code:
globalvar instanceID = id;
And then in the object that needs to call it:
Code:
event_perform_object(instanceID,ev_alarm,0);
If you're placing the instance in the room editor, the former code snippet could also go in its "creation code".

If all instances need to be affected, just do it like this (replace objectName with the name of the object):
Code:
event_perform_object(objectName,ev_alarm,0);
The 0 at the end is the number of the alarm. So if you use alarm 0 it remains the same, but if you use alarm 6 you'd set it to 6.

I hope this helps!
 
H

Heath Close

Guest
Thank you both very much.... I will try both ways... but I would need to look into how to make a user event... I'll tackle it in the morning, thank you
 
Top