Hello, I have a question about the or statement. Basically an or statement should be this or that. Right? That’s what I thought at first, but now I’m getting confused basically I have a combo system. If it’s 1 or 3 then it prints out 1 or 3, but even if it’s 2 it still prints out 1 or 3. So what’s the problem here? I know this might be a dumb question, but any help is appreciated.
if combo == 1 or 3 then
combo += 1
print(" 1 or 3") -- Keeps printing 1 or 3 even if combo is 2.
elseif combo == 2 or 4 then
combo += 1
print("2 or 4")
elseif combo == 5 then
combo += 1
print("5")
elseif combo == 6 then
combo = 1
print("6)
end
local combo = 1
if combo == 1 or combo == 3 then
combo += 1
print(" 1 or 3")
elseif combo == 2 or combo == 4 then
combo += 1
print("2 or 4")
elseif combo == 5 then
combo += 1
print("5")
elseif combo == 6 then
combo = 1
print("6")
end
in the or statements, you are checking the combo value at first but only checking if a number exists after, which will always return true. Example:
lets say that combo = 2. When checking if combo == 1 or 3 then, we will check if combo is 1 first. It isn’t, so we check the second option which is just 3. since 3 exists, it returns true and the statement executes even though combo isn’t 1 or 3.
You should use if combo == 1 or combo == 3 then instead.