event_perform

Performs a given event of the calling instance.

Syntax:

event_perform(type, numb);


Argument Description
type The type of event to perform. See below.
numb The specific event constant or value, if one is necessary (otherwise, just use 0).


Returns: N/A


Description

This function will perform 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 and the game will not modify anything to make it trigger itself manually, for example if you choose to perform a keyboard press event, the event will be triggered but relevant key will not be recognised as having been pressed. Or if you perform an alarm event, the alarm counter will not be set to -1 but rather continue to count down.

Constants

The table below outlines all the constants that are included in GameMaker: Studio 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, while their number values are marked with italic text and these are the same as the return values for the event_number variable:

Name Description
ev_create Create event.
ev_destroy Destroy event
ev_step Step event
   ---- ev_step_normal Step
   ---- ev_step_begin Begin Step
   ---- ev_step_end End Step
ev_alarm Alarm event
   ---- 0 ... 11 The number relevant to which of the 12 alarms you wish to trigger the event of
ev_keyboard, ev_keypress, ev_keyrelease Keyboard/Keyboard Pressed/Keyboard Released
   ---- any key code vk_space or ord('W') for example.
ev_mouse Mouse event
   ---- ev_left_button Left button held down on object
   ---- ev_right_button Right button held down on object
   ---- ev_middle_button Middle button (or clickable wheel) held down on object
   ---- ev_no_button No buttons held down
   ---- ev_left_press Left button just pressed on object
   ---- ev_right_press Right button just pressed on object
   ---- ev_middle_press Middle button (or clickable wheel) just pressed on object
   ---- ev_left_release Left button just released on object
   ---- ev_right_release Right button just released on object
   ---- ev_middle_release Middle button just released on object
   ---- ev_mouse_enter Mouse just entered object's bounding box
   ---- ev_mouse_leave Mouse just left object's bounding box
   ---- ev_mouse_wheel_up Mouse wheel scrolled upwards
   ---- ev_mouse_wheel_down Mouse wheel scrolled downwards
   ---- ev_global_left_button Left button held down anywhere
   ---- ev_global_right_button Right button held down anywhere
   ---- ev_global_middle_button Middle button (or clickable wheel) held down anywhere
   ---- ev_global_left_press Left button just pressed anywhere
   ---- ev_global_right_press Right button just pressed anywhere
   ---- ev_global_middle_press Middle button (or clickable wheel) just pressed anywhere
   ---- ev_global_left_release Left button just released anywhere
   ---- ev_global_right_release Right button just released anywhere
   ---- ev_global_middle_release Middle button just released anywhere
ev_collision Collision with an object
   ---- The index of the object to check. object1 for example.
ev_other One of the actions listed under 'Other'
   ---- ev_outside Whether the instance is outside of the room
   ---- ev_boundary Whether the instance is intersecting the boundary
   ---- ev_game_start Only triggered at the start of the game
   ---- ev_game_end Only triggered at the end of the game
   ---- ev_room_start Only triggered at the start of a room
   ---- ev_room_end Only triggered at the end of a room
   ---- ev_no_more_lives If all lives are depleted (if lives==0)
   ---- ev_no_more_health If all health is depleted (if health==0)
   ---- ev_animation_end If the object's sprite has reached the end of its animation
   ---- ev_end_of_path If the object has reached the end of a path it is following
   ---- ev_close_button If the window's Close button has been pushed
   ---- ev_user0... ev_user15 One of the 16 available user events.
ev_draw Draw event. NOTE: This event cannot be forced outside of a draw event and the constants and the constants are only for identifying the event when performed in these cases.
   ---- ev_draw_begin The draw begin event.
   ---- ev_draw_end The draw end event.
   ---- ev_draw_pre The pre draw event.
   ---- ev_draw_post The post draw event.
   ---- ev_gui The draw gui event.
   ---- ev_gui_begin The draw gui begin event.
   ---- ev_gui_end The draw gui end event.


Extended Example

To help understand how this function can be use, please look at the following few examples:

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.


Back: Generating Events
Next: event_perform_object
© Copyright YoYo Games Ltd. 2018 All Rights Reserved