ゲームで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 関数を間違って書いたのか、回避策を書いたのか知っていますか?
ありがとう!