计算机控制/ Lua程序循环不能保持信号输出

我正在尝试编写一个程序,使用os.time()函数获取时间并用其改变红石输出。当重新启动时,该程序被设置为自动运行,但由于我重新启动以使程序重新启动,它会中断然后再次启动代码。我已经尝试在多个位置和形式上使用循环来更新时间变量,但没有成功。任何帮助将不胜感激。(如果循环能够起作用,我仍然对循环的解决方案持开放态度)

代码:

shell.run("time")
x = os.time()
print(x)
if x > 18.500 then
  redstone.setOutput("left", true)
elseif x < 6.500 then
  redstone.setOutput("left",true)
else redstone.setOutput("left",false)
end
sleep(2)
os.reboot()
点赞
用户7152887
用户7152887

你不应该需要使用 os.reboot(),你的代码应该像这样简单:

while true do
  shell.run("time")
  x = os.time()
  print(x)
  if x > 18.500 then
    redstone.setOutput("left", true)
  elseif x < 6.500 then
    redstone.setOutput("left",true)
  else
    redstone.setOutput("left",false)
  end
  sleep(2)
end
2017-05-15 19:49:09