So if debounce == false then and if not debounce then functions the same. Are there are actually the same? Because when using it with the if statement. They work same.
When you say
if debounce == false then
You are actually checking if the value of debounce
is false
. This statement will then return true if you set debounce = false
.
On the other hand,
if not debounce then
will return true if (not debounce) is true. not is an logic operator that will return the opposite value - so not true
will return false
and not false
will return true
.
This statement is different than the previous one. Say we choose the value of debounce to be nil
, then saying if not debounce then
will actually work, and the if statement will run. This is because when using the not
operator on nil
, Lua will read the statement as true
if used inside of an if statement. However if you check nil == false
, that statement is false, but (not nil) == true
returns true.
Hope this helps.
Using not in front of a bool reverses the bool value.
If the debounce is true and you do not debounce
Then the debounce will = false
if the debounce is false and you do not debounce
Then the debounce = true