Ok so I was working was wokring on this one part for a Chess Game I'm making. When I ran into a small little error which I couldn't really place. So I created a separate script to work it out and now I'm even more confused.
--Conceptual Problem local NumVar = 2 local NumVar2 = 8 local Answer = 1 if Answer == NumVar then print("Horay!1") end if Answer == NumVar2 then print("Horay!2") end if Answer == NumVar or NumVar2 then print("Should Not Ever print") end
This is what I tested in my separate script. Now I was under the impression that because the variable Answer is not equal to either NumVar or NumVar2, the print("Should Not Ever print") would never print. Yet for some reason it does, and I can't quite figure out why. Anyone have any ideas?
Here is a bit confusing and I completely understand the confusion. But here's the thing...This is not the ideal way to use if/or statements.
Using a logic gate you would find that or is a way of checking if either thing is true. The right way to have done it would have been:
if Ans == NVar or Ans == NVar2 then bla bla bla
The reason being is that OR looks for if either one is true, because you only did ...or NumVar2 then...
it will just print because you didnt give any extra information, just that other variable. By default it's true since well that's hard to explain for me at my current knowledge but it's not false so it will print.
Just be careful when doing something...Here's some advice:
if variable/boolean/number == condition or variable/boolean/number == condition then
if variable/boolean/number or variable/boolean/number == condition if variable/boolean/number == condition or variable/boolean/number
Look up on conditional statements and experiment with how they work, you'll eventually get it! Mark this answer if it helped :3