i'm trying to do simplest of things:
however current code just prints first message 2 times and exits:
print("welcome. you have 2 options: play or leave. choose.")
input = io.read()
if input == "play" then
print("let's play")
end
if input == "leave" then
print("bye")
end
if input ~= "play" or "leave" then
print("welcome. you have 2 options: play or leave. choose.")
end
what is wrong here? any help appreciated, thanks
An if statement will only execute once. It doesn't jump to other parts of the program. To do that you need to wrap your input code in a while loop and break out when you get a valid response:
while true do
print("welcome. you have 2 options: play or leave. choose.")
local input = io.read()
if input == "play" then
print("let's play")
break
elseif input == "leave" then
print("bye")
break
end
end
Read more about loops here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With