Ive seen a lot of variables with no values and looks like this:
local examplevariable local example2variable
And people use these variables as if it did have a value
Also how do people use variables with the value of nil? Is it the same thing?
local examplevariable = nil
local examplevariable
and local examplevariable = nil
are essentially the same. The former is what you would call a 'variable declaration' while the latter is both a 'declaration' and 'initialization' of the variable examplevariable
to nil
. A place you might see this often is with a debounce variable:
local debounce --declaration: at this point it is nil ... --nil is a 'falsy' value --line 07 will evaluate to true if debounce is nil if not debounce then debounce = true print("Doing some debounced thing") wait(1) debounce = nil end