2

我正在尝试编写一个从 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()
4

1 回答 1

1

你不应该需要 os.reboot(),你的代码应该看起来像这样:

while true
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-15T19:49:09.200 回答