Discuss and collaborate on GML scripts

You are not logged in.

#1 2008-08-29 12:57:21

Registered: 2007-10-17
Posts: 110

Order of the events

Well I'm not sure where I should post this, maybe at the faq forum of the gmc, maybe somewhere else. For 90% of the people it's pretty useless information, however sometimes it's very usefull to know which event is handled first. And if you don't look out for mistakes here it can easily lead to hard-to-find runtime bugs.
But I've been doing some research according the events:

GM works everything event by-event: first is 1 event handled for all objects/instance, then it moves to the second etc...

The order in which all instances are "handled" during an event can be in 2 ways:
(A) events are handled in order of DEPTH, instances with the highest depth are handled first..
(B ) events are handled in order of OBJECTID, so the instance with the lowest object id (not instance id) is handled first.. In case where there are 2 instances of the same object, it's handled in order of the instance id..

So the order as far as I could discover

  • creation code (A). This is the "ctrl-right-click-creation-code" from the room editor, don't confuse it with the creation event

  • creation event (A)

  • Game start (A)

  • Room creation code (A) (again, not the "event" but the code you can put in the room editor)

  • Room start event (A)

  • Draw event (A) - This is a bit strange drawing event, since the "updating" from image_index doesn't happen...

  • begin step event (B )

  • ---alarm0 timer updating---

  • alarm[0]

  • ---alarm1 timer updating---

  • alarm[1] - This is the general scheme, notice however that if the alarm turns "0" the event is triggered: but the step after that the alarm is still updated to -1.

  • keyboard events (B )- This is simply in order in which they also appear at the gm-editor, except for the any key (which is list executed after all keyboard events) and the "no-key" (which I simply couldn't test...)

  • keyboard press events (B )

  • keyboard release events (B )

  • mouse events (B ) - this is in some strange order

  • normal left

  • global left

  • normal middle

  • global middle

  • normal right

  • global right

  • pressed events (as above)

  • release events (as above)

  • mouse up/down

  • mouse enter/leave


  • ---position updating with "hspeed/vspeed*---

  • ---position updating with *paths*---

  • path end (B ) - the instance is now at it's "NEW" position for the step!

  • Outside room (B )

  • Intersect boundary (B )

  • Boundary view[X] (B ) - It handles all views in order (from lowest to highest)

  • outside view[X] (B ) - see above

  • ---Collision calculating--- in case of a solid collision the instances are set back NOW (notice: while the position changes, to <x,y>previous, it isn't the same as saying: <x,y>=<x,y>previous since the <x,y>previous itself ISN'T updated!)

  • Collision (B ), also the collisions are handled in "B" order: first with the smallest object id, and the instance id as tiebreaker

  • end step (B )

  • Draw event (A) - the draw events are all (also the one before) executed for each view in order of view index

  • ---updating the image_index---

  • animation end event (A)


It's a bit hard to determine what a "round" is, but I think best would be to call it from "begin step event to animation end event".. The first few rounds are "special" rounds (the draw event because it isn't followed by an updating from the image index)...

There are a few events not listed here these can be in 2 groups:
instance_destroy, room_end and game_end These 3 events are all executed immediatelly after the calling event has "triggered" the event..
nomorelives, nomorehealth and creation Those events are executed at the right moment of "triggering": it even "interupts" the current event...

Well that's everything I discovered so far...

Last edited by paul23 (2008-08-29 13:01:55)


#2 2008-08-29 13:43:15

Registered: 2007-08-18
Posts: 1,240

Re: Order of the events

Good stuff, paul23, keep it coming! smile

Here is a list of similar GMC topics for future reference:

I know there are others, so if you spot a good one, make a note of it. Hopefully, they will help us create a definitive event order list.

Last edited by xot (2008-08-30 03:07:31)

Abusing forum power since 1986.


Board footer

Powered by FluxBB