Local and Global Variables

From Frictional Wiki
< HPL3
Revision as of 09:57, 13 August 2020 by TiMan (talk | contribs) (Created page with "{{Hpl3ScriptingGuideMenuBasic}} {{shortPageTitle}} Local and global variables are variables that have a certain scope compared to the script in which it is located in. There...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search


Local and global variables are variables that have a certain scope compared to the script in which it is located in. There are certain levels of scope to a script, there is the function's scope, then there is the local scope, then there is the global scope.

A function's scope consists of everything within its braces ({ }). Normal variables as shown above will only work in a function unless carried over to another function.

A local variable's scope is the whole entire script, so if you made a local variable, then you wouldn't have to worry about having to carry it over from function to function. The downside to it is that you can't use the value of the local variable in commands. It is mostly used to check and see if the player has done multiple things within the map to make something greater happen.

To do: Add code example more explanation about scopes


Timers