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.
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
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)
}
Code:
position_destroy(x - 2*global.TileSize,y)
instance_create(x - 2*global.TileSize,y, obj_NoWallsHere)