Scopes are what define the range of functionality to a variable or function. This specifically applies in Lua to local variables & functions. When you define a variable or function with local, its scope is defined by the innermost block of code you define it in.
Example of various scopes:
local x =15-- scope is script-wide, x can be accessed anywhere inside of this scriptfunctiona()local first =true-- first can only be accessed throughout a()'s code blockif first thenlocal second =123-- can only be accessed within this if statementprint(second) -- Output: 123endprint(second) -- nil, cannot access that variable anymoreprint(first) -- Ouput: true | we can access this variable since we're still inside of the function's code blockend
Another example showing a function's scope:
localfunctionoutputTable(t)localfunctionoutput(t)for k, v inpairs(t) doprint(k, v)endendoutput(t) -- output function is only accessible inside of outputTableendoutputTable({1, 2, 3}) -- works, outputTable's scope is script-wideoutput({1, 2, 3}) -- will return an error, output is inaccessible since it's not inside the current scope, it is inside of outputTable.