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

What does this mean in an If statement?

Asked by 8 years ago

This is probably a very basic question... if not gameThing and gui.Visible then

How does this work? I thought when using variables in an if statement, you need to specify a determinant. Example: if gameThing ~= nil and gui.Visible == false then

2 answers

Log in to vote
0
Answered by
BlackJPI 2658 Snack Break Moderation Voter Community Moderator
8 years ago

The way that if statements work is that they takes a conditional statement and either execute the following block of code if the condition is true, or skip it if the condition is false.

So essentially you could say if true then and it would always execute the code block. Same goes for if false then, except it would never execute the code block. All that is required for the if statement condition is that it evaluates to a boolean (true/false) value.

0
Alright, I understand now. So does saying 'if not Value' basically mean 'if Value == false' ? ShiningWindow 127 — 8y
0
Right! BlackJPI 2658 — 8y
0
Thank you much! ShiningWindow 127 — 8y
Ad
Log in to vote
0
Answered by
Link150 1355 Badge of Merit Moderation Voter
8 years ago

Following BlackJPI's explanation, not x evaluates to true if and only if x is neither nil or false. Since nil represents a lack of useful value (nothing), you can use this to test whether a value exists.

So if not gameThing and gui.Visible then would mean if gameThing exists (and is not explicitly false) and gui is Visible then do the following.

Answer this question