• 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!

GML [SOLVED] What is the order of code execution within WITH construction? What’s going on inside it?

MartinK12

Member
Take for example this simple code from manual:
Code:
var inst;

inst = noone;
with (obj_ball)
   {
   if str > other.str inst = id;
   }
if inst != noone target = inst;
Is it executed like loop, creating ds_list?
So with statement takes each instance of obj_ball in order (probably from low to high obj_ball id?), checks its str variable with calling object, then takes another obj_ball instance until all are checked?
And only then the rest of the code is executed?

I understand with statement, just want to know what is going on inside it :)
 

TsukaYuriko

☄️
Forum Staff
Moderator
You can verify this yourself by outputting the instance IDs to the debug console using show_debug_message inside the with statement's body.
 
B

Bayesian

Guest
In the example you posted no ds_list is created, it works as a loop and is made to be used as a script. It goes through each obj_ball in order of creation and if more that one has str greater than the calling instance's str they will be overwritten and only the last one that passed is used. You can of course return DSs if you want to do that instead.
 

MartinK12

Member
Thank You @TsukaYuriko for your reply. I did it and it works like a loop - I got list of instance ids in no particular order. But as @Bayesian clarified it works as a loop and checks instances in order of creation code. Thank You guys :)
 
Last edited:
Top