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

A "if" for two different values? [closed]

Asked by
lucas4114 607 Moderation Voter
9 years ago

So.... I need a way to do a "if" thing for two values, this:

if RandomBall and Ball1BeingUsed == ?????????? then

The ???????????? is the problem, I mean, that RandomBall is a number value, and Ball1BeingUsed is a bool value, so they're two different value types. So that means how would I do that, I'm guessing I'll try a "and" like this "== 1 and false then" but I'm not sure it works........

1
For future reference: and makes the if function fire ONLY if both conditions are valid! or will fire the function if EITHER condition is valid! alphawolvess 1784 — 9y

Locked by alphawolvess, dyler3, TurboFusion, and adark

This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.

Why was this question closed?

2 answers

Log in to vote
2
Answered by
dyler3 1510 Moderation Voter
9 years ago

Lol, you had it almost exactly correct. This'll work:

if RandomBall== 1 and Ball1BeingUsed == false then --You can change the '1' or 'false' if you need to

It doesn't matter how many conditions there is, which I think was your problem. You don't assign them both to the same value when you use "and", you're just setting up another condition. Hopefully you understand what I'm trying to say. Anyways, if you have any questions or problems, please leave a comment below. Hope I helped :P

3
`Ball1BeingUsed == false` is the same as `not Ball1BeingUsed`, the latter being more readable. :D adark 5487 — 9y
0
It works...! lucas4114 607 — 9y
0
Awesome! Glad I could help :P (Upvoted adark) dyler3 1510 — 9y
Ad
Log in to vote
1
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
9 years ago

I'm not sure what you're trying to ask here.

and is a binary operator (meaning it works on 2 things). If the first operand is true or truthy (that is, if it isn't false or nil), the second is returned, otherwise the first is returned.

or is also binary, but is the opposite. If the first operand is not true or truthy, the second is returned, otherwise the first is returned.

In your example,

if RandomBall == 1 and not Ball1BeingUsed then --This is what I assumed you meant.

--First, it checks `RandomBall == 1`. If it is indeed 1, this becomes:

if Ball1BeingUsed then

--and if it isn't:

if false then

--Which obviously does nothing.

--Next, if `Ball1BeingUsed` is `true` or not-`nil` then the `if` statement runs. Otherwise, nothing happens again.