So local variables are variables that are local to the function. Global Variables are variables that can be used in multiple functions in the script.
So in this example:
local GlobalVariableNameBlah
local function RandomFunctionName()
local LocalVariableNameBlah
end
GlobalVariableNameBlah is a global variable and can be changed from anywhere in the script.
However LocalVariableNameBlah is only alive as long as the function is running. And only things inside that function can access that variable.
So for example:
If I wanted to change the Global Variables value I could do it inside the function.
Also note that I could have made it a string or a bool. I just chose an integer.
local GlobalVariableNameBlah
local function RandomFunctionName()
local LocalVariableNameBlah
GlobalVariableNameBlah = 20
end
I can't change the Local variable outside of this function in another function. So for example
local GlobalVariableNameBlah
local function RandomFunctionName()
local LocalVariableNameBlah
GlobalVariableNameBlah = 20
end
local function OtherFunctionName()
LocalVariableNameBlah = 20
GlobalVariableNameBlah = 30
end
It's also important to note that these functions would not run unless I say below them
RandomFunctionName()
OtherFunctionName()
If they were non local functionsI could call them above them like so:
local GlobalVariableNameBlah
RandomFunctionName()
OtherFunctionName()
function RandomFunctionName()
local LocalVariableNameBlah
GlobalVariableNameBlah = 20
end
function OtherFunctionName()
LocalVariableNameBlah = 20
GlobalVariableNameBlah = 30
end
Anything declared inside a function is local yes.
Hope this answered your question.
1 comment
Oh I see what you're saying. So basically the variable is waiting to be defined which happens once you call the function, thanks!