This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
PetruZ's profile picture

[Question]

Started by PetruZ, 13 May 2012 - 06:23 PM
PetruZ #1
Posted 13 May 2012 - 08:23 PM
Hi.

I am trying to do something like this:
if x == "a" or "b" or "c" then

But when I do that, I can type whatever and it works and not only A B or C.


So does "or" even exist or am I doing it wrong?

Thanks
- PetruZ.
Luanub #2
Posted 13 May 2012 - 08:38 PM
Here is the proper if syntax


if a == "z" or a == "y" or a == "x" then
MysticT #3
Posted 13 May 2012 - 08:40 PM
It should be:

if x == "a" or x == "b" or x == "c" then
the keyword "or", returns true if one of the expressions is true. The expressions in this case are x == "a", x == "b", x == "c". They are three different expressions, the way you did it tested the expressions x == "a", "b", "c", so it compares x with "a", and checks if "b" is nil or "c" is nil (wich will never happen, so returns always true).
PetruZ #4
Posted 13 May 2012 - 08:48 PM
Ah thanks very much ! :P/>/>