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

What is or?

Asked by
Vezious 310 Moderation Voter
9 years ago

I've seen or a few times. But its not really used much, and wiki doesn't have much information about or does anyone have a concrete description of or?

2 answers

Log in to vote
4
Answered by
Legojoker 345 Moderation Voter
9 years ago

In practically all scripting languages (at least that I've come across) there is a basic set of boolean logic that helps a programmer combine conditions to make a yes or no decision. or is one of the boolean operators that performs as a useful tool in a conditional statement. This word has various uses, and I will try to go through each one.

local keyIn = true
local doorOpen = true
if keyIn == true or doorOpen == true then
    print("Success!")
end

The word or used in this small bit of code is inside an if-then statement, as part of a conditional. Success! will be printed in the Output if keyIn is true OR doorOpen is true. In other words, only one of them has to be true in order for Success! to print. Here's another example.

while keyIn == true or not doorOpen do
    wait(1)
    print("Alright.")
end

In this example, the conditional is in a while loop, so this loop will continue until the conditional is false. In order for a conditional with an or statement to be false, both portions of the statement must be false. Because I used the word not in front of doorOpen, that portion of the statement can return true if doorOpen is false. keyIn is working the same as in the prior if statement, where it returns true if the statement is equal; in other words keyIn has to equal true to return true for the conditional. Here's one last more complex example:

local plr = game.Players.LocalPlayer
local character = plr.Character or plr.CharacterAdded:wait()

Unlike the previous code, this statement is using a listening event. Or is used here to say that character has to equal plr.Character, but if this part of the conditional returns nil, it will wait for the listening event CharacterAdded to find a character for the player referenced. This example is the most complex out of the three so it's fine if you don't understand it initially; I presented it simply to give insight to more intricate use of boolean logic. I hope this helped, and if it did, don't forget to upvote!

Ad
Log in to vote
3
Answered by
1waffle1 2908 Trusted Badge of Merit Moderation Voter Community Moderator
9 years ago

or is a logical disjunction. If you have two conditions a and b, and at least one of them is true, then a or b is true.

More specifically, the result is the first value that is true, in the case of non-boolean objects; if a is false and b is 5, then a or b is 5.

If none are true, the value is the last:

false or nil is nil

nil or false is false

Answer this question