Skip to content

Instantly share code, notes, and snippets.

@bazay
Last active December 2, 2024 08:35
Show Gist options
  • Save bazay/5de8526ec34aeff6465e9bfe0bbe9b97 to your computer and use it in GitHub Desktop.
Save bazay/5de8526ec34aeff6465e9bfe0bbe9b97 to your computer and use it in GitHub Desktop.
GML Event Ordering.md

Aside from the obvious usefulness of having just a function to act as a conditional in your code, I believe the only difference worth noting is that the events occur at set times during the step, known as the event order. If you have very complex code that is organised into different stages throughout the step, this can matter.

The documentation is quite lacking so here are the results of some research. Each event runs for each instance in the order of the resource tree before moving on to the next event. The exception to this are Alarms, (which are explained below), movement and collision (which seem to be intertwined), and the draw events, which follow the order of highest(+) depth to lowest(-) depth instead of resource tree order (yes, this is really how depth works :O)

Initialisation Events:

  • Create Event
  • Instance Creation Code
  • Game Start
  • Room Creation Code
  • Room Start

Step Events:

  • Begin Step
  • Timeline Moment (object order)
  • Alarm[0 .. 11] (lowest alarm, earliest object -> lowest alarm, latest object -> next highest alarm, earliest object.. * etc..)
  • Keyboard state check
  • Keyboard pressed
  • Keyboard release
  • Mouse state check
  • Global Mouse state check
  • Mouse Pressed
  • Global Mouse pressed
  • Mouse release
  • Global Mouse released
  • Normal Step
  • Movement and Collision events (Gravity applied to speed, speed applied to position. No idea about friction.)
  • Other – Outside Room
  • Other – Intersect Boundary
  • *End Step

Draw Events:

  • Pre-draw
  • Draw begin
  • Draw normal
  • Draw end
  • Post-draw
  • Draw GUI begin
  • Draw GUI normal
  • Draw GUI End

Some other things to note..

  • Due to the positioning of the Alarm Event, if you set an alarm to 1 in the Begin Step Event, it will execute its code immediately after the Begin Step Event.
  • When you use instance_create, the Create Event of the instance you’re creating is run immediately. However, the instance is not included in the list of current instances until the event is over for all current instances. This means that if instance_create was called during the Normal Step Event, the created instance won’t run its Normal Step Event, but will run all subsequent events such as End Step and Collision Events.
  • Gamemaker monitors your inputs in real time, meaning that if you have something like a keyboard press event, you can trigger that press event on every step if you press and release the key within one frame over and over.
  • The key/mouse events can only run once per step, regardless of how many times you press and release them within that step.
  • You can set an instance’s depth variable during the draw events, but it won’t update until after the draw events, because GM only reads it once at the beginning (not exactly sure where, but definitely before Begin Draw) and uses that depth to order the draw events for each instance.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment