2017-05-15 34 views
2

我想寫一個程序,從os.time()函數獲取時間並使用它來更改紅石輸出。重新啓動時,程序設置爲自動運行,但由於我重新啓動以使程序重新啓動,它會中斷,然後再次啓動代碼。我已經在幾個地方嘗試過循環,並在不重啓的情況下更新時間變量,但無濟於事。任何幫助,將不勝感激。 (我仍然願意與循環的解決方案是否會工作)computercraft/lua程序循環無法維持信號輸出

代碼:

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() 

回答

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 
+0

謝謝!猜猜我是過於複雜的東西... –

+0

任何人都希望基於遊戲時間的照明系統,這裏有一個可行的解決方案,使用ComputerCraft的計算機 –