Legacy GM [SOLVED]Is there a way to re-order object execution?

Hi!

So there is a problem in our game right now caused by the order in which step events of multiple objects are being executed. To fix the problem, I need to be able to change the order that the objects execute.

I thought depth would fix this, no that case. From what I've seen and read depth only effects the draw event.
I tried changing the creation order within the room editor. Still nothing. Objects executed in the same order.
I tried re-placing the object I want to execute last, after placing the others. Still didn't work. Same order of execution.
I even tried just changing the objects order within the resource tree in hopes that it might just work. Still nothing.

I am aware of the begin and end step functions. Using them is not preferable due to how things are structured and work so I'd like to avoid that if possible.

Does anyone know of a way to re-order the execution of an object?

Thanks in advance.
 
Last edited:

Jobo

Member
GMC Elder
I would say if you need to be order dependent, then you will need to use the Begin Step and End Step events. Otherwise you are getting into a very fragile state (perhaps this is what you are seeing now) where maybe it will work and maybe it won't. Alternatively you could perform these events through scripts instead and thereby maintain a correct order of execution.
 
I would say if you need to be order dependent, then you will need to use the Begin Step and End Step events. Otherwise you are getting into a very fragile state (perhaps this is what you are seeing now) where maybe it will work and maybe it won't. Alternatively you could perform these events through scripts instead and thereby maintain a correct order of execution.
Yeah I gave in and went with the begin/end step options. Is there a reason that we have no way to order object execution though? Like execution_depth or something? It would be very useful for these situations but I wouldn't know if there was some sort of reason as to why such things can't be done.
 

Tsa05

Member
Generally, this can be problematic as instances get created/destroyed, changed, activated/deactivated or many other circumstances (collision checks, etc). You can definitely change the instance order in the room for Create events, but again, the order can get out of sync as the game runs.

If you have specific things that you know you want to execute in a specific order, you can make use of the various if_*_exists() functions or, more reasonably, keep items in a list. It is unclear what specifically you are trying to do that is this order-specific, so I can only offer vague ideas here, but basically, you can do things like:

Code:
if (condition which sets off a series of things happening){
    for(loop through the list){
        with(list[index]) do_the_thing, or event_perform(suchAndSuch)
    }
}
Or this:

Code:
global.whichThingShouldRun = -1;
if (condition which sets off a series of things happening){
    global.whichThingShouldRun = 0;
}

And then, over in your conflicting objects, add this:

if(global.whichThingShouldRun>=0 AND id == global.listOfObjects[ global.whichThingShouldRun]){

    do whatever needs to be done;
    global.whichThingShouldRun += 1;
}
 
R

renex

Guest
Have a controller object call the code in the correct order. This is the easiest way to make it reliable.
 

TheouAegis

Member
Okay, here's the breakdown of how it works.

1) Instances that are placed in the room manually are created in the order described by the Instance Creation Order list, or on a FIFO order if you don't mess with the Creation Order.

2) The Create event of instances placed in the room manually are thus run in order as described by the Instance Creation Order list, or on a FIFO order if you don't mess with the Creation Order.

3) 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.

4) 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.

5) The with command will execute code in Reverse Instance order. In other words, the last instance created (regardless of what object_index it has) will run the code in the with command first, then the next newest instance, and so forth. In other words, the oldest instance in the room runs its code last.

NOTE: The Instance Creation Order will not take effect until you close the Creation Order list and close the room editor as well. (This was a head-scratcher for me until I figured out what was going on.)


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.
 
R

renex

Guest
This kind of undocumented behavior is exactly why I have a single controller object cascade all the code in my games.

I get things to happens when I want them to.
 
Okay, here's the breakdown of how it works.

1) Instances that are placed in the room manually are created in the order described by the Instance Creation Order list, or on a FIFO order if you don't mess with the Creation Order.

2) The Create event of instances placed in the room manually are thus run in order as described by the Instance Creation Order list, or on a FIFO order if you don't mess with the Creation Order.

3) 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.

4) 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.

5) The with command will execute code in Reverse Instance order. In other words, the last instance created (regardless of what object_index it has) will run the code in the with command first, then the next newest instance, and so forth. In other words, the oldest instance in the room runs its code last.

NOTE: The Instance Creation Order will not take effect until you close the Creation Order list and close the room editor as well. (This was a head-scratcher for me until I figured out what was going on.)


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.
I tried what you said about the step event being based off the instance creation order and it didn't work. I even went as far as restarting game maker after changing the order before compiling again and still the objects did not execute their step event in the order of creation. I have however since solved the issue by just giving in and making use of the begin and end step events.
 

TheouAegis

Member
No, I never said the step event was based on instance creation order. I said the step event was based on object order. Each object is processed in order going down the resource tree. The oldest instance of that object runs its step event, then the next oldest, then so on. Once all of that object have run their step events, the next object runs its step event.
 
No, I never said the step event was based on instance creation order. I said the step event was based on object order. Each object is processed in order going down the resource tree. The oldest instance of that object runs its step event, then the next oldest, then so on. Once all of that object have run their step events, the next object runs its step event.
My bad, I misunderstood. Bottom line is though there is no in built way to order instance execution though right? Aside from controlling it through some other object or by any other manual user created means.
 

TheouAegis

Member
No, not really. I just use an array/priority queue of all ids in whatever order i want them to run, which is ultimately how it should be done anyway. Or as renex said, have a controller use to control order.
 
N

Nikles

Guest
I'm sorry to bring this up again but in case of persistent objects...
Code:
ROOM1                   ROOM2
obj_persistent -------->obj_persistent
                        obj_new
If both these objects execute, let's say, a Room Create event, the order of execution is defined by their depth (moreover the persistent instance's creation order cannot be controlled by the room editor)

The greater the depth value, the later it will execute its Room Create event (I chose this event as an example because this is what I've been working with right now).

This is not documented (not that I'm aware of) but I'm kind of relying on it for now (and it works).
 
Top