GameMaker [SOLVED] Begin Step

Neptune

Member
I've created an object resource called o_checks, and I'm trying to gather some game information and store it in global variables, for other objects to use each step.

For instance, rather than calling:
Code:
if instance_exists(o_player_parent)
{
x = o_player_parent.x;
}
I can just say:
Code:
x = global.player_x;
I'm wondering if the "Begin Step" event is where I should put these checks. Do all objects with a "Begin Step" run their events before the main step events are run?

Any information is appreciated.
 

obscene

Member
1 ) All Begin Steps execute, then all Step execute, then all End Steps execute.
2 ) Those two code blocks are entirely different and I'm not sure how that's related.
 

Neptune

Member
Thanks for reply @obscene
The second code block is demonstrating what I'm trying to achieve with the "o_checks" object.
If an object calls "x = o_player.x" and an instance of o_player does not exist... I'm in trouble -- if I'm only ever checking for a 'real' in global.player_x, I don't ever have to worry.

So the checks object would do all the messy "if instance_exists", "if point_distance", etc... and store the data in global variables. It'll also help avoid duplicate function calling.

Anyways, Begin Step will work great -- the data will be up-to-date and ready to use for each step of the game.
Thanks!
 

TheouAegis

Member
Or just code your game responsibly so that you don't need instance_exists() checks. I almost never use instance_exists(). It has a place in code, but I doubt this is necessarily such a place.
 

Neptune

Member
Checking if the player exists is a dumb-down example, and currently is not a check I'm even doing. However, there are unavoidable cases -- unless I want to go out of my way to simply avoid a handy function.
 

TheouAegis

Member
In what way would you be going out of your way to avoid slowing down your code? How is it going out of your way to make sure you never have a situation where you'd call an instance that doesn't even exist? If you're looping through a list of possibilities, then instance_exists() can be a valuable function.

Anyway, also use Begin Step if you need to reset variables that will be updated in the I/O events (e.g., keyboard and mouse checks), since Begin Step runs before any other events each step. This usually works better for the mouse and gamepad than the keyboard, though.
 

Neptune

Member
The instance_exists just works for me, because there are a variety of creatures that may or may not "come out" depending on weather, time etc.

Will definitely add the mouse checks to the Begin Step, thanks!
 
Top