我试图在游戏中为基于 lua 的计算机制作程序。虽然当它运行时它的行为很奇怪
--Tablet
oldpullEvent = os.pullEvent
os.pullEvent = os.pullEventRaw
while true do
term.clear()
term.setTextColor( colors.white )
term.setCursorPos(1, 1)
print("Please Enter Password:")
input = read("*")
incorrect = 0
while incorrect < 3 do
if input == "qwerty" then
print("Password Correct, Unlocking")
else
if incorrect < 3 then
incorrect = incorrect + 1
print("Password incorrect")
print(3 - incorrect, " tries remaining")
else
print(3 - incorrect, "tries remaining, locking phone for 1m")
local num = 0
while num < 60 do
if num < 60 then
term.clear()
term.setTextColor( colors.red )
term.setCursorPos(1, 1)
num = num + 1
print(60 - num, "s remaining")
sleep(1)
else
incorrect = 0
end
end
end
end
end
end
os.pullEvent = oldpullEvent
当它运行时,它以“请输入密码:”开头,输入“qwerty”它想要的密码后,它会无限循环“密码正确,解锁”。当我输入不正确的密码时,它不会运行 else 语句中的任何代码,只是返回输入密码屏幕。没有错误代码或崩溃。任何了解 lua 的人都知道我是否编写了 while/if/elseif 函数错误或变通方法。
谢谢!