event_perform

This function will perform the code in the specified event, with the designated argument, for the instance running the code. There are many options here which allow complete simulation of all possible events, but note that this literally just performs all the code in the event; the game will not modify anything to make it trigger itself manually.

For example if you choose to perform a keyboard press event ev_keypress, the event will be triggered but the relevant key will not be recognised as having been pressed. Or if you perform an alarm event ev_alarm, the alarm counter will not be set to -1 but rather continue to count down.

NOTE Asynchronous events can be called using event_perform_async.

The table below outlines all the constants that are included in GameMaker for referencing event types, as well as their number value. The events themselves are marked in bold text and are the same as the return values of the event_type variable (to be passed into the first argument of this function), while their number values are marked with italic text and are the same as the return values for the event_number variable (to be passed into the second argument of this function): 

Event Type Constant & Event Number Constant
ConstantDescription
ev_createCreate event
ev_destroyDestroy event
ev_cleanupClean Up Event
ev_stepStep event
   ---- ev_step_normalStep
   ---- ev_step_beginBegin Step
   ---- ev_step_endEnd Step
ev_alarmAlarm event
   ---- 0 ... 11The number relevant to which of the 12 alarms you wish to trigger the event of
ev_keyboard, ev_keypress, ev_keyreleaseKeyboard/Keyboard Pressed/Keyboard Released
   ---- any key codevk_space or ord("W") for example.
ev_mouseMouse event
   ---- ev_left_buttonLeft button held down on object
   ---- ev_right_buttonRight button held down on object
   ---- ev_middle_buttonMiddle button (or clickable wheel) held down on object
   ---- ev_no_buttonNo buttons held down
   ---- ev_left_pressLeft button just pressed on object
   ---- ev_right_pressRight button just pressed on object
   ---- ev_middle_pressMiddle button (or clickable wheel) just pressed on object
   ---- ev_left_releaseLeft button just released on object
   ---- ev_right_releaseRight button just released on object
   ---- ev_middle_releaseMiddle button just released on object
   ---- ev_mouse_enterMouse just entered object's bounding box
   ---- ev_mouse_leaveMouse just left object's bounding box
   ---- ev_mouse_wheel_upMouse wheel scrolled upwards
   ---- ev_mouse_wheel_downMouse wheel scrolled downwards
   ---- ev_global_left_buttonLeft button held down anywhere
   ---- ev_global_right_buttonRight button held down anywhere
   ---- ev_global_middle_buttonMiddle button (or clickable wheel) held down anywhere
   ---- ev_global_left_pressLeft button just pressed anywhere
   ---- ev_global_right_pressRight button just pressed anywhere
   ---- ev_global_middle_pressMiddle button (or clickable wheel) just pressed anywhere
   ---- ev_global_left_releaseLeft button just released anywhere
   ---- ev_global_right_releaseRight button just released anywhere
   ---- ev_global_middle_releaseMiddle button just released anywhere
ev_gestureA gesture event (Tap, Drag, Flick, Pinch or Rotate)
   ---- ev_gesture_tapA single click/touch and release has been detected for an instance
   ---- ev_gesture_double_tapTwo quick touches/clicks and releases have been detected for an instance
   ---- ev_gesture_drag_startThe beginning of a drag gesture has been detected for an instance
   ---- ev_gesture_draggingA touch/click has been held and moved for an instance
   ---- ev_gesture_drag_endThe release of the touch/click from a drag has been detected for an instance
   ---- ev_gesture_flickThe release of a touch/click from a drag had enough movement for a flick event to be detected for the instance
   ---- ev_gesture_pinch_startTwo touches and a straight movement have been detected for an instance
   ---- ev_gesture_pinch_inThe movement between two touches for an instance has been detected as inwards
   ---- ev_gesture_pinch_outThe movement between two touches for an instance has been detected as outwards
   ---- ev_gesture_pinch_endThe release of one (or both) touches for a pinch has been detected for an instance
   ---- ev_gesture_rotate_startThe movement between two touches for an instance has been detected as a rotation
   ---- ev_gesture_rotatingThe movement between two touches for an instance has been detected as rotating
   ---- ev_gesture_rotate_endThe release of one (or both) touches for a rotation has been detected for an instance
   ---- ev_global_gesture_tapA single click/touch and release has been detected anywhere in the room
   ---- ev_global_gesture_double_tapTwo quick touches/clicks and releases have been detected anywhere in the room
   ---- ev_global_gesture_drag_startThe beginning of a drag gesture has been detected anywhere in the room
   ---- ev_global_gesture_draggingA touch/click has been held and moved anywhere in the room
   ---- ev_global_gesture_drag_endThe release of the touch/click from a drag has been detected anywhere in the room
   ---- ev_global_gesture_flickThe release of a touch/click from a drag had enough movement for a flick event to be detected anywhere in the room
   ---- ev_global_gesture_pinch_startTwo touches and a straight movement have been detected anywhere in the room
   ---- ev_global_gesture_pinch_inThe movement between two touches anywhere in the room has been detected as inwards
   ---- ev_global_gesture_pinch_outThe movement between two touches anywhere in the room has been detected as outwards
   ---- ev_global_gesture_pinch_endThe release of one (or both) touches for a pinch has been detected anywhere in the room
   ---- ev_global_gesture_rotate_startThe movement between two touches anywhere in the room has been detected as a rotation
   ---- ev_global_gesture_rotatingThe movement between two touches anywhere in the room has been detected as rotating
   ---- ev_global_gesture_rotate_endThe release of one (or both) touches for a rotation has been detected anywhere in the room
ev_collisionCollision with an object
   ---- The index of the object to check.obj_enemy for example.
ev_otherOne of the actions listed under 'Other'
   ---- ev_outsideWhether the instance is outside of the room
   ---- ev_boundaryWhether the instance is intersecting the boundary
   ---- ev_outside_view0...7Whether the instance is outside the given view (0 to 7)
   ---- ev_boundary_view0...7Whether the instance is interesecting with the boundary of the given view (0 to 7)
   ---- ev_game_startOnly triggered at the start of the game
   ---- ev_game_endOnly triggered at the end of the game
   ---- ev_room_startOnly triggered at the start of a room
   ---- ev_room_endOnly triggered at the end of a room
   ---- ev_animation_endIf the object's sprite has reached the end of its animation
   ---- ev_animation_updateAnimation event that runs every step for objects that use skeletal animations
   ---- ev_animation_eventAnimation event that runs for skeletal animations as assigned in the skeletal animation tool
   ---- ev_end_of_pathIf the object has reached the end of a path it is following
   ---- ev_user0... ev_user15One of the 16 available user events.
   ---- ev_broadcast_messageBroadcast Message event used for sprites and sequences
ev_drawDraw event. NOTE This event cannot be forced outside of a draw event and the constants are only for identifying the event when performed in these cases.
   ---- ev_draw_normalThe normal draw event.
   ---- ev_draw_beginThe draw begin event.
   ---- ev_draw_endThe draw end event.
   ---- ev_draw_preThe pre draw event.
   ---- ev_draw_postThe post draw event.
   ---- ev_guiThe draw gui event.
   ---- ev_gui_beginThe draw gui begin event.
   ---- ev_gui_endThe draw gui end event.

 

Syntax:

event_perform(type, numb);

ArgumentTypeDescription
typeEvent Type ConstantThe type of event to perform (see the table above).
numbReal or Event Number ConstantThe specific event constant or value. No matter if an event has sub-events or not, its "default" event is always referred to by event number 0 (e.g. the Create event only has a single sub-event which has event number 0, the "normal" Step and Draw events can be referred to by their constants (ev_step_normal and ev_draw_normal respectively) or by their event number 0)

 

Returns:

N/A

 

Extended Example

event_perform(ev_keypress, ord("W"));

This would perform the event associated with Keyboard Check Pressed "W" key (without actually generating a keyboard press).

event_perform(ev_step, ev_step_begin);

This would perform the Begin Step event (if called from any of the step events it would cause the begin step event code to be run twice).

event_perform(ev_create, 0);

This would perform the Create event of the instance.