In code, “scope” refers to how much of your code can reference a particular variable.
@thomas6 is absolutely correct. As he says, there are two types of scope: local and global.
Generally, we talk about a variable’s scope as being the module, function or while, do, if or else statement that it is declared in. For example:
local name = "myModule" local function printSomething( text ) if (text == nil) then print("Nothing") lastprinted = "nothing" else local pre = "I want to print: " print( pre..text ) lastprinted = pre..text end end
The code above is very bad, but it illustrates this:
name is local to the Lua module and can be used by all code in this .lua file
text is local to the function and can be used by all the code in this function only
lastprinted is global and can be used by the whole application - even other Lua modules
pre is local to only the code between the else and the end of the if statement, not the whole function