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

What dose 'if not' keyword means?

Asked by 1 year ago

I am trying to learn debounce, but I am confuse. When I see people use 'if not' I don't know what it means. Thank you.

2 answers

Log in to vote
1
Answered by 1 year ago
Edited 1 year ago

if not is basically checking if a statement is false. Some examples would be as follows:

if not 2+2 == 4 then
    --  this code will never run
end

-- that can also be written like follows

local value = false
if 2 + 2 == 4 then
    value = true
end

if value == false then
    -- do this
end

--[[ that way of writing it works however its a lot less convenient to hit = twice than to just type the below code block]]

if not value then
    -- do this
end

When writing an if statement you should keep in mind that no matter what you put as the parameter, the script will always translate it to true or false. For example, in the above code I wrote if not 2+2 == 4 then which translates to "if 2+2 being equal to 4 is a false statement then run this code. In this case the code will never run because 2+2 obviously always equals 4. Let me know if you still don't understand and I'll explain a bit deeper.

0
Very well explanation! NotThatFamouss 605 — 1y
Ad
Log in to vote
0
Answered by
Antelear 185
1 year ago

You've might've saw this in some scripts or tutorials, which is understandable! I'm going to just explain it as shortly as I can so you don't get bored;

if not examp_value --> same as if examp_value==false.if examp_value--> same asif examp_value==true`.

This is the script's way of translating the not keyword in the if statement into checking if the condition is false, if you were to just do if examp_value it'll just check if it's true, instead. So, it can be worded like this:

"if not true then" or "if true then"

sorry if this is vague, but I tried, hope this helps! And if it does, mark it as the answer. xd

Answer this question