Ive seen a lot of variables with no values and looks like this:
1 | local examplevariable |
2 | local example 2 variable |
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?
1 | 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:
01 | local debounce --declaration: at this point it is nil |
02 |
03 | ... |
04 |
05 | --nil is a 'falsy' value |
06 | --line 07 will evaluate to true if debounce is nil |
07 | if not debounce then |
08 | debounce = true |
09 | print ( "Doing some debounced thing" ) |
10 | wait( 1 ) |
11 | debounce = nil |
12 | end |