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

GMS2 - How can I ensure one create event runs before another?

G

GDP234

Guest
For my game, I have a controller object. In that controller objects create event I have defined some DS grids and assigned values to those grids. I also am planning to have multiple enemies and to anticipate this I have made an enemy parent object. In the enemy parent objects create event I want to define the enemies health and other variables based on the information defined in the ds grid from the controller object. For example, I have a ds grid which contains the enemies in the game and all their stats (health, damage, armour, etc.) I want to take the value stored in the ds grid for the enemy's health and assign it to the enemyHealth variable in the enemy parent object.
However, it appears like the parent objects create event is running before the controller objects create event because I get an error saying that the ds grid is not set before reading it. (These variables are all global and I have tried with multiple variables from the create event.) So I think I need to make sure the controller object runs its create event first but I am not sure if there is a way to do so?

P.s. This is my first time posting on here so sorry if I didn't explain well.
 

samspade

Member
Object/instance order goes in (unsurprisingly) creation order as create events run upon creation. So if you are placing them in the room editor, you can change the order by using the instance creation order tab (make sure to use the one for the room, not the one for the layer). If you are creating them by code, make sure to create them in the order you want them to run.

Another way to do this would be to make the controller object persistent and initialize it in some sort of init room.
 
G

GDP234

Guest
Object/instance order goes in (unsurprisingly) creation order as create events run upon creation. So if you are placing them in the room editor, you can change the order by using the instance creation order tab (make sure to use the one for the room, not the one for the layer). If you are creating them by code, make sure to create them in the order you want them to run.

Another way to do this would be to make the controller object persistent and initialize it in some sort of init room.

Thanks for the quick reply, I thought I was doing that but turns out I was just changing where it was on the instance's layers.
 
Top