Your issue is with this line:
if resp1 == "Yes" or "yes" then
These are two separate expressions, and in Lua, everything except nil
and false
are truthy values, so it will pick that if
statement to run, because a string in Lua, even an empty one, evaluates to true
as far as conditions are concerned. If it helps you understand, think of it like this:
if (resp1 == "Yes") or ("yes") then
If you actually wanted to compare resp1
against two values, you would do it like this:
if resp1 == "Yes" or resp1 == "yes" then
However, this is a simpler solution for what you're trying to achieve:
if resp1:lower() == 'yes' then
In fact, you could clean up your loop, too. Make it more readable. Make use of multi-line strings instead of multiple print
calls and break
as well.
repeat
resp1 = io.read():lower() -- read in lowercased input
if resp1 == 'yes' then
print[[Well alright then, come on in.
Let me just take your blood sample like all the rest and you'll be good to go.]]
break -- exit from the loop here
elseif resp1 == 'no' then
print[[Oh, your not? Then why are you up here?
Oh nevermind then. None of my business anyways. All I'm supposed to do is take a blood sample for everyone who enters the town.
So let us get that over with now, shall we?]]
break
else
print'Please respond with Yes or No'
end
until false -- repeat forever until broken