Order of script execution with instance_create and the 'create' event

E

Erian

Guest
As the title suggests, I am using a script to create an instance in my game world, and that instance places a few more instances during its 'create' event.
I am now puzzled by the order of execution, and here's why.

After the initial script creates the instance (obj_Pattern), it continues by placing walls at random positions in the game. There is one object though, which is a wall blocker. No walls will be placed on the wall blocker.

obj_Pattern places objects in a predetermined fashion, including walls and wall blockers.
On those tiles where obj_Pattern places wall blockers, it first destroys everything on the tile and then places a blocker.

The problem is that when I run the game and create random levels, very often there will be a wall.
However, if the initial script were to continue before Game Maker executes the 'create' event of obj_Pattern, I would expect the 'create' event to destroy any walls that are there.
If Game Maker on the other hand executes the 'create' event first, I would expect there to be wall blockers, in which case there should be no walls either.


Here is some code that I use.

This determines whether or not to place a wall. It comes after creating obj_Pattern.
Code:
if (random_range(0,10) < 3 && !position_meeting(i,k,obj_NoWallsHere))
{
   instance_create(i,k,obj_Wall)
}
This is a bit of code that first destroys all that is on a tile before placing the wall blocker. It is executed in the 'create' event of obj_Pattern
Code:
position_destroy(x - 2*global.TileSize,y)
instance_create(x - 2*global.TileSize,y, obj_NoWallsHere)
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Moderator
The Create Event for each instance is run the moment that it is created. So if you have a script like:

Code:
blah blah
blah
do something
instance_create(x, y, instance);
do more stuff
do something else
blah
Then the create event of the instance being created in the code will run COMPLETELY before the rest of the code that created the instance continues to run.
 
E

Erian

Guest
The Create Event for each instance is run the moment that it is created. So if you have a script like:

[...] the create event of the instance being created in the code will run COMPLETELY before the rest of the code that created the instance continues to run.
So I will have to find out exatly why it is placing the walls on a position that is blocking them. I'll see where the problem in that is. Thank you!
 

TheouAegis

Member
What bugs me is you said the pattern object first destroys everything in a particular position and then puts a wall blocker or whatever there. What code are you using for that part? How are you finding and destroying all instances currently at the position of wherever the pattern wants to place a wall blocker? Your issue very well could be elsewhere, it could be related to the order of operations... But without delving into the rest of your code, this is the first place personally I would look. I have seen way too often logic errors with code around similar processes. Like, if you are just doing a single instance position check, I would suspect and Theory that should work fine enough, but maybe there is an issue elsewhere where multiple instances are being placed on the same spot anyway and so a single instance position check will only destroy the first instance at that position, not all of them.
 
Top