我正在製作一個小程序,用戶輸入一個數字並且程序生成一個隨機數。但是程序只是在用戶輸入一個數字後立即停止。我不知道是什麼導致了這一點。希望這裏有人可以幫助我解決這個問題,我對lua很感興趣,並且對自己編程。以lua結束的程序
print("Do you want to play a game?")
playerInput = io.read()
if playerInput == "yes" then
print("What is your number?")
numGuess = io.read()
rad = math.random(0,100)
while numGuess ~= rad do
if numGuess < rad then
print("To low")
elseif numGuess > rad then
print("to high")
else
print("You got the number")
end
print("What is your number?")
numGuess = io.read()
end
else
print("You scared?")
end
你沒有提到程序是如何退出的,我假設這是因爲你試圖將一個字符串與一個數字進行比較。這可能會幫助你閱讀你想要的類型:http://stackoverflow.com/questions/12069109/getting-input-from-the-user-in-lua –
在我的系統上它不會停止,它會失敗錯誤消息,它沒有在你的系統上做到這一點? – Schollii