【发布时间】:2014-04-15 09:47:41
【问题描述】:
我正在制作一个小程序,用户输入一个数字,程序会生成一个随机数。但是程序会在用户输入数字后立即停止。我不知道是什么原因造成的。希望这里有人可以帮助我解决这个问题,我是 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
【问题讨论】:
-
您没有提到程序是如何退出的,我认为这是因为您试图将字符串与数字进行比较。这可能会帮助您阅读所需的类型:stackoverflow.com/questions/12069109/…
-
在我的系统上它不只是停止,它失败并显示错误消息,你的系统上没有这样做吗?
标签: lua