选项 4 在不执行预期功能的情况下退出程序

我正在编写 computercraft minecraft 模组上的程序,但每当我尝试选项 4 时,程序会直接退出而不执行任何操作:

os.pullEvent = os.pullEventRaw
while true do
term.clear()
term.setCursorPos(1,1)
print ("欢迎来到 F-SecOS")
print ("1)初始化")
print ("2)关闭程序")
print ("3)电源控制")
print ("4)rednet 控制")

input = io.read()

if input == "1" then
 term.clear()
 term.setCursorPos(1,1)
 print ("正在初始化 10%")
 print ("|")
 sleep(1)
 term.clear()
 term.setCursorPos(1,1)
 print("正在初始化 25%")
 print("/")
 sleep(1)
 term.clear()
 term.setCursorPos(1,1)
 print("正在初始化 50%")
 print("--")
 sleep(1)
 term.clear()
 term.setCursorPos(1,1)
 print("正在初始化 75%")
 print(".\.")
 sleep(1)
 term.clear()
 term.setCursorPos(1,1)
 print("正在初始化 90%")
 print("|")
 sleep(1)
 term.clear()
 term.setCursorPos(1,1)
 print("初始化成功")
 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)打开外门")
 print("2)关闭外门")
 print("3)打开内门")
 print("4)关闭内门")
 print("5)打开中门")
 print("6)关闭中门")
 print("q)退出")
 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)打开端口")
 print ("2)关闭端口")
 print ("3)发送消息")
 print ("4)未使用的功能")
 print ("5)未使用的功能")
 print ("q)退出")
 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 控制没有 while true do 是因为会带来一整套问题

点赞
用户6000025
用户6000025

你在代码中间有这个代码块:

if input == "4" then
 break
  end

在第2和第3个输入之间, 因此它在这里捕获输入并在到达代码末尾之前停止, 在那里你还有另一个 if input == "4",其实际逻辑是你想要做的。

2016-03-01 04:59:19