Local variables are created with the local statement. Their scope is limited to the block where they are declared.
Global variables are stored in the "global environment table" which is generally accessible to all functions. Local variables are only visible to the block in which they are "seen". For example:
In this example if there was another variable "x" somewhere else in the program, it would not be affected by the local variable x inside foo.
Be aware that if you redefine a local variable you get a new one of the same name. Eg.
If you want to change an existing local variable, do not use the word local again, eg.
See Also ...
Lua base functions
(Help topic: lua=local)
Enter a search string to find matching documentation.
Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.
Gammon Software support
Forum RSS feed ( https://gammon.com.au/rss/forum.xml )