SOLVED Is it possible to change the order of handling of instances due to each other?

G

ghostinecatnewyear

Guest
Hello everyone! You know that instances are handled in order due to order of their creation. For example the instance "A" has been created and then the instance "B" has been created. Each step the A's code will be executed firstly and only then the B's one. So I want to know wether it's possible to do so the B's code is executed firstly and only then the A's.
 

DukeSoft

Member
Yes, the depth of the instance does that (goes from highest depth (furthest away) to lowest (closest to you)). Also you have the 'Before Step" and "After Step" events to change some ordering.
 

TheouAegis

Member
What version of GMS are you using?

In GMS1:
The hierarchy of Step Event execution is Object-Instance ordering. In other words, all instances of object_index 0 will run their codes first in order of instance id, then all instances of object_index 1 will run their codes in order of instance id, and so forth.

Draw events are handled on a Depth-Reverse Instance order. In other words, the newest instance with the highest depth is drawn first, then the next newest instance with the highest depth is drawn, and so forth. So if all instances are at the same depth, the newest instance is drawn first and the oldest is drawn last.

...

So if you want a certain object to always run its code before any other objects, that object must be higher up in the hierarchy of object resources.
In other words, make object B object A.
 
P

ph101

Guest
Or in other other words, move the object you want to execute first (talking step event not draw event here ) to the top of the resource tree and the one you want to execute last to the bottom.
 
D

dannyjenn

Guest
There used to be a way to disable the events, such that you could have a single controller object which called all the events in all the other objects. By doing that, you could have full control over the order. But I highly doubt you can still do this in GMS2.

Yes, the depth of the instance does that (goes from highest depth (furthest away) to lowest (closest to you)).
I'm pretty sure that that was only true of the draw event, not the other events. And I don't think it's true at all anymore, since GMS2 replaced the depth system with the layer system.
 
I

immortalx

Guest
@ghostinecatnewyear are you talking about different objects, or different instances of the same object? If it's the latter, I guess an easy way to do that is, the moment you need instance B to run its code first, destroy instance A and "re-create" it. It will get assigned a greater id and if I'm not mistaken its step-event code will get executed after instance B from then on.
 
Top