Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Is not and false are the same?

Asked by 5 years ago

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.

0
I guess they do(Only for a bool value because theres only true and false!!) because you could do if debounce == not true or you could use if debounce == false or for short you could do if debounce ~= true which means not true for short mudathir2007 157 — 5y
0
In a way not and false are the same, but you can't do false false or false true in coding and have to use not true or not false. LostPast 253 — 5y

2 answers

Log in to vote
0
Answered by
chomboghai 2044 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

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.

0
Why are some people so good at explaining things. XD LostPast 253 — 5y
0
Thanks but you mean when local Debounce = false but you used if not debounce then, it is true? cherrythetree 130 — 5y
0
yes in the context of if then statements. LostPast 253 — 5y
Ad
Log in to vote
0
Answered by
LostPast 253 Moderation Voter
5 years ago
Edited 5 years ago

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

0
If you do if not debounce then it always means if debounce == false. User#19524 175 — 5y
0
yes but in the context of if then's I was jumping to the conclusion. not deb will pass as true when deb is false and not deb will pass as false when deb is true. LostPast 253 — 5y
0
i mean with my debounce scripts, that's how i've seen the logic. it always runs only when false User#19524 175 — 5y

Answer this question