Lua 选项4在不执行预期功能的情况下退出程序
我正在computercraft minecraft mod上编写一个程序,每当我尝试选项4时,它都会退出该程序而不做任何操作:Lua 选项4在不执行预期功能的情况下退出程序,lua,Lua,我正在computercraft minecraft mod上编写一个程序,每当我尝试选项4时,它都会退出该程序而不做任何操作: os.pullEvent = os.pullEventRaw while true do term.clear() term.setCursorPos(1,1) print ("Welcome to F-SecOS") print ("1)initialize") print ("2)shutdown") print ("3)power control") print
os.pullEvent = os.pullEventRaw
while true do
term.clear()
term.setCursorPos(1,1)
print ("Welcome to F-SecOS")
print ("1)initialize")
print ("2)shutdown")
print ("3)power control")
print ("4)rednet control")
input = io.read()
if input == "1" then
term.clear()
term.setCursorPos(1,1)
print ("intitializing 10%")
print ("|")
sleep(1)
term.clear()
term.setCursorPos(1,1)
print("initializing 25%")
print("/")
sleep(1)
term.clear()
term.setCursorPos(1,1)
print("initializing 50%")
print("--")
sleep(1)
term.clear()
term.setCursorPos(1,1)
print("initializing 75%")
print(".\.")
sleep(1)
term.clear()
term.setCursorPos(1,1)
print("initializing 90%")
print("|")
sleep(1)
term.clear()
term.setCursorPos(1,1)
print("initializing 100%")
print("/")
sleep(1)
term.clear()
term.setCursorPos(1,1)
print("F_sec initialized")
sleep(1)
term.clear()
term.setCursorPos(1,1)
print("F_SecOS V1.8")
break
end
if input == "2" then
os.shutdown()
end
if input == "4" then
break
end
if input == "3" then
while true do
term.clear()
term.setCursorPos(1,1)
print("1)open outer door")
print("2)close outer door")
print("3)open inner door")
print("4)close inner door")
print("5)open middle door")
print("6)close middle door")
print("q)exit")
CI = io.read()
if CI == "1" then
rs.setOutput("left",true)
end
if CI == "2" then
rs.setOutput("left",false)
end
if CI == "3" then
rs.setOutput("right",true)
end
if CI == "4" then
rs.setOutput("right",false)
end
if CI == "5" then
rs.setOutput("bottom",true)
end
if CI == "6" then
rs.setOutput("bottom",false)
end
if CI == "Q" or CI == "q" then
break
end
if input == "4" then
term.clear()
term.setCursorPos(1,1)
print ("1)open ports")
print ("2)close ports")
print ("3)send message")
print ("4)unused function")
print ("5)unused function")
print ("q)exit")
RI = io.read()
if RI == "1" then
rednet.open ("top")
end
if RI == "2" then
rednet.close ("top")
end
if RI == "q" or RI == "Q" then
end
end
end
end
end
问题是rednet控件不起作用,我输入4,程序结束时不做任何操作,不清除屏幕或打印文本,我已尝试所有我知道的方法来修复它,但相同的问题不断发生,或者我收到错误消息
顺便说一句,rednet Control中没有while true do的原因是因为它带来了一组全新的问题您有一段代码在中间:
if input == "4" then
break
end
在输入2和3之间,因此它在这里捕获输入并在它到达代码末尾之前停止,在这里您还有另一个
如果输入==“4”
,并且具有您想要执行的操作的实际逻辑。请正确格式化和缩进您的代码。此外,还可以简化它,以便我们能够更快地发现问题。