Does GameMaker have getters and setters for built-in variables?

OliverSB

Member
I know that in order to create getter and setter scripts in GameMaker you use scripts and call them but is GameMaker executing getter and setter scripts behind the scenes for variables like 'sprite_width' or are these variables already set before the step event or does it execute a getter every time you read the value?

Would it be more efficient to set sprite_width in a variable like 'sWidth = sprite_width' and refer to 'sWidth' instead every time you know the value is going to change or will this make virtually no difference.
 

Simon Gust

Member
They are avaliable and calculated before your own code begins to run.
I'm not sure but I believe they even update instantly. Say you have x and y, the built-in variables bbox_left, right, top, bottom depend on x and y (and mask_index etc.), if you change x or y, they may get updated right then and there.
That aside, some built-in variables are a different data type unlike normal variables (which are floating point values), which may get your code faster depending on the situation.
On top of that, calling scripts will slow down your game compared to having raw code.
 

Yal

šŸ§ *penguin noises*
GMC Elder
Most of the built-in variables are read-only (think of them more like constants that updates to correspond to changes - for instance, sprite_width becomes negative if you have a negative image_xscale). They update instantly when the thing they measure is updated, unless otherwise specified in the manual (just like how updating direction/speed updates hspeed/vspeed instanteously). Any variable that isn't (e.g. keyboard_string, score, x) can be manipulated like any other variable.
 
Top