Generating eventsAs you know, GameMaker is completely event driven. All actions happen as the result of events. There are a number of different events. Creation and destroy events happen when an instance is created or destroyed. In each step, the system first handles the begin step events. Next it handles the alarm events, keyboard and mouse events and next the step event. After this the instances are set to their new positions after which the collision event is handled. Finally the end step events are handled after which the draw event is used to draw the instances (note that when there are multiple views the draw event is called multiple times in each step). You can also apply an event to the current instance from within a piece of code. The following functions exist:
event_perform(type,numb) Performs event numb of the indicated type to the current instance. The following event types can be indicated:
ev_createWhen there are multiple events of the given type, numb can be used to specify the precise event. For the event type ev_alarm numb can range from 0 to 11. For the ev_keyboard, ev_keypress. and ev_keyrelease event types you have to use the keycode for the key. For ev_mouse events you can use for numb the following constants:
ev_left_buttonFor the collision event you give the index of the other object. For the event type ev_other you can use for numb the following constants:
ev_outsideFor the ev_step event type you can use the following constants for numb:
ev_step_normalFinally for the ev_trigger event type you should use the constants that you can specify when defining these events.
event_perform_object(obj,type,numb) This functions works the same as the function above except that this time you can specify events in another object. Note that the actions in these events are applied to the current instance, not to instances of the given object!
event_user(numb) In the other events you can also define 16 user events. These are only performed if you call this function. numb must lie in the range 0 to 15.
event_inherited() Performs the inherited event. This only works if the instance has a parent object.
You can get information about the current event being executed using the following read-only variables:
event_type* Type of the current event begin executed.
event_number* Number of the current event begin executed.
event_object* The object index for which the current event is being executed.
event_action* The index of the action that is currently being executed (0 is the first in the event, etc.).