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

SOLVED Is this a stupid question?

K

Kaplutnoir

Guest
So, long story short:


if( something ) {

instance_destroy();
instance_create_whatever();

}

if I put instance_destroy() on the second line instead of the first, and instance_create on the first line instead of the second, will it resolve instance_create first or does it resolve at the same time as instance_destroy()?
I've been wrecking my brain over a problem all night and this somehow solved it for me. So I was wondering if that really did it?
 

TailBit

Member
The whole event will perform, not depending on the order at all, the instance will just be marked for deletion on the next cleanup (after step end event ???)
 

samspade

Member
The code runs sequentially, so there is a different. Sort of. So in the code you posted, instance destroy will run first then instance create will run. However, specific to instance destroy the function call instance_destroy runs the destroy event but the object isn't actually destroyed until the end of the event in which the function instance destroy is called. Quoting from the manual: "It is worth noting that when you destroy an instance, its destroy event is called immediately after the code or action that calls the destroy function. Also, although the destroy event is performed, the instance is not immediately removed from the game, and it will continue to perform the code contained in the current event. Only when the current event is over will it be removed from the game."

Assuming that was the code for the entire event, you can think of it as function like this (assuming the if statement ran):
  1. Run the destroy event
  2. Create instance whatever
  3. End the event
  4. Destroy the instance
If you reversed the order it would go like this:
  1. Create instance whatever
  2. Run the destroy event
  3. End the event
  4. Destroy the instance
And again, it is important to note that this is a specific quirk of how instance_destroy works. If you replaced destroy and create with debug messages for example, they would just execute in the order that they're run.
 
Top