'local' keyword?


i'm throwing this into off-topic because while setting up a bunch of code, i stumbled across something that i couldn't find an answer to, but it's nothing i'll lose sleep over.
if you enter local into the code editor, gamemaker studio 2.2.5 ( and possibly other versions ) will highlight it as if it's a constant, and middle-clicking on it doesn't give me any answer, nor does searching the manual.
the first time i saw it i thought that maybe i declared a variable somewhere called local that i completely forgot about, but even after making a new test project it was there, and i still don't know what it does.
i tried passing it through a show_debug_message and draw_text function and it gives me an error saying that the variable isn't set, so i don't even have a starting point for guesses.
i even had a suspicion about it being the 'local' equivalent of the global keyword, but that didn't do anything either when i tried using it to declare a variable.

this isn't really that deep, and maybe it's just some leftover constant either from a previous build or some kind of plan for incoming features, but i'm curious to know.
does anyone actually know what this constant is / does / is used for?


Could be either old or upcoming. There are a whole stack of function names and keywords that are reserved internally.

It was about four years ago I realised I couldn't used the word 'struct' anywhere and now lo and behold, we have structs.


Don't you have to use the word "global" when initializing global variables? Maybe in the future we'll use "local" instead of "var" to initialize local variables. (I hope not).


🐧 *penguin noises*
GMC Elder
It's been around for a long time - it's in GMS1, possibly even GM8. My theory is that it can be used to differentiate between a var or globalvar and an instance variable with the same name... but then again, self could be used for the exact same purpose and definitely works. And also, using the same variable names for different scopes to ghost out a variable is a bad idea anyway, so... x3


Friendly Tyrant
Forum Staff
I'm pretty sure "local" is used when there is potential variable naming conflicts between scopes in instances. Like, if you use "with" to change scope to an instance, and that instance has a variable "hp", and you want to add a local variable "hp" to it, then you'd use "local" to ensure that the correct variable is being accessed, eg:

var hp = 10;
with (obj_Player)
hp += local.hp;
Haven't tested, and I'm not 100% sure, But I'm fairly sure this is why the keyword exists.



🐧 *penguin noises*
GMC Elder
If it has any reason to exist, it probably should be documented :p
I always assumed it was either deprecated or "GM behind-the-scenes" use only since it's not in the manual, just like e.g. the hidden functions that stands in for D&D actions pre-GMS2.


🐧 *penguin noises*
GMC Elder
Awesome! Can't wait to find out what it actually does after all these years... x3


King of Raccoons
Nocturne: Hey so some people where wondering what Local does, so what does it do?

Devs: oh that,...no idea.

manual: keyword<local> takes you to local assets page