• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Order of code execution

Hello there.

I have a problem with order of code execution in objects. AFAIK, in GMS1 code runs "from first to last" object as they placed in asset tree. Say you have:
  • o_abc
  • o_def
  • o_hij
If you add to step "show_message(string(object_get_name(id)))" you get following: o_abc, o_def, o_hij
And if you manually move them in asset tree, order of execution WILL change.

But that not seems to be the case anymore in GMS2.3. From what i've seen it runs code in "from newest to oldest" order and seemingly absolutely cannot be changed.

Is that really so? Or i miss something important?

Please, tell me if im wrong and there is a way to affect this in GMS 2.3.
 

Slyddar

Member
You should not base your logic on that order being consistent. Use the instance creation order section, or add checks to ensure code runs how you want it to.
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
You have been relying on undocumented behaviour which is something you should never do as it will change at some point... The manual clearly states that you can't guarantee the order of execution except using the very clearly defined systems in place already in the IDe, eg: begin/step/end events, instance creation order in the room editor, etc...

 
Use the instance creation order section
You mean, in room editor? Yeah, that was the literally first thing i tried.
And yes, it affects order of code in "Create" event. Instances really are created in order how it was set in room editor.
Does not affect order of "Step" at all, it lives its own life.

Nice, thanks. So, a lot of rework should be done. Or revert to the old version to even finish the job. Thanks a lot.
 
Top