Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

What does it mean to have a variable with no value or equal sign?

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

1 comment

0

It is required in other programming languages to initialize a variable and may cause an error in the compiler. In Lua this is not required.

2 answers

✓ Accepted answer

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

This discussion is preserved as it was. New answers, comments, and votes are closed.