我目前正在使用Lua进行一个简单的“猜数字”游戏。我正在通过iPad上的应用程序进行编程,名为TouchLua +。其中一种游戏模式是你有一定的时间来猜测数字。我认为要这样做,我会创建一个从给定时间开始倒计时的协程。出于某种原因,我不能在协程运行时输入数字。谁能帮忙?这是我到目前为止。Lua Coroutine错误
target = math.random(1, 100)
coroutine.resume(coroutine.create(function()
for i = 1, roundTime do
sleep(1000)
sys.alert("tock")
end
lose = true
coroutine.yield()
end))
repeat
local n = tonumber(io.read())
if (n > target) then
print("Try a lower number.\n")
elseif (n < target) then
print("Try a higher number.\n")
else
win = true
end
until (lose or win)
return true