Generating events
As you know, Game Maker 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_create ev_destroyWhen 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_step
ev_alarm
ev_keyboard
ev_mouse
ev_collision
ev_other
ev_draw
ev_keypress
ev_keyrelease
ev_trigger
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_right_button
ev_middle_button
ev_no_button
ev_left_press
ev_right_press
ev_middle_press
ev_left_release
ev_right_release
ev_middle_release
ev_mouse_enter
ev_mouse_leave
ev_mouse_wheel_up
ev_mouse_wheel_down
ev_global_left_button
ev_global_right_button
ev_global_middle_button
ev_global_left_press
ev_global_right_press
ev_global_middle_press
ev_global_left_release
ev_global_right_release
ev_global_middle_release
ev_joystick1_left
ev_joystick1_right
ev_joystick1_up
ev_joystick1_down
ev_joystick1_button1
ev_joystick1_button2
ev_joystick1_button3
ev_joystick1_button4
ev_joystick1_button5
ev_joystick1_button6
ev_joystick1_button7
ev_joystick1_button8
ev_joystick2_left
ev_joystick2_right
ev_joystick2_up
ev_joystick2_down
ev_joystick2_button1
ev_joystick2_button2
ev_joystick2_button3
ev_joystick2_button4
ev_joystick2_button5
ev_joystick2_button6
ev_joystick2_button7
ev_joystick2_button8
ev_outsideFor the ev_step event type you can use the following constants for numb:
ev_boundary
ev_game_start
ev_game_end
ev_room_start
ev_room_end
ev_no_more_lives
ev_no_more_health
ev_animation_end
ev_end_of_path
ev_close_button
ev_user0
ev_user1
ev_user2
ev_user3
ev_user4
ev_user5
ev_user6
ev_user7
ev_user8
ev_user9
ev_user10
ev_user11
ev_user12
ev_user13
ev_user14
ev_user15
ev_step_normalFinally for the ev_trigger event type you should use the constants that you can specify when defining these events.
ev_step_begin
ev_step_end
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.).