我試圖做簡單的事情:如果在Lua
- 程序打印第一條消息,並等待用戶輸入
- 用戶類型在「玩」或「離開」
- 如果用戶類型在「玩」程序打印「讓我們玩」並退出(現在)
- 如果在「離開」程序打印「再見」用戶類型和退出
- 如果東西比「玩」或「離開不同用戶類型「程序 打印第一個爛攤子年齡,等待用戶再次輸入
但是當前的代碼只是打印第一條消息2次,然後退出:
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
這裏有什麼問題?
if (input ~= "play") or "leave" then
字符串"leave"
,或與此有關的任何字符串,被認爲是truthy值:所理解的任何幫助,感謝
什麼是「輸入」? – hjpotter92
我編輯過的代碼是:input = io.read()。問題在於在任何用戶輸入程序之後再打印第一條消息並退出 – hexbreak