Difference between revisions of "HPL3/Scripting/Scripting Guide/Local and Global Variables"

From Frictional Wiki
Jump to navigation Jump to search
Line 13: Line 13:
 
{{todo|Add code example more explanation about scopes}}
 
{{todo|Add code example more explanation about scopes}}
  
{{NavBar|HPL3/Scripting/The Update method|The Update method|HPL3/Scripting/HPL3 Scripting Guide|HPL3 Scripting Guide|HPL3/Scripting/Timers|Timers}}
+
{{NavBar|HPL3/Scripting/Scripting_Guide/Sequences|Sequences|HPL3/Scripting/HPL3 Scripting Guide|HPL3 Scripting Guide|HPL3/Scripting/Enums|Enums}}
  
 
[[Category:HPL3 Scripting]]
 
[[Category:HPL3 Scripting]]
 
[[Category:English]]
 
[[Category:English]]

Revision as of 14:09, 13 August 2020


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


Enums