This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
slayerdwb's profile picture

[Lua][Question] In game time based redstone activation

Started by slayerdwb, 16 April 2012 - 09:01 AM
slayerdwb #1
Posted 16 April 2012 - 11:01 AM
I'm trying to write a program to redstone.setOutput("back", true) if in game time is between 6:30pm and 5:30am and redstone.setOutput("back", false) if between 5:30am and 6:30pm. I have searched google and browsed through pretty much all the code i could find related to my program type. My time is based on 24hour as i couldn't figure out how to differentiate between am and pm, any help is greatly appreciated.

Spoiler

while true do
shell.run("clear")
local nTime = os.time()
print( "Time: "..textutils.formatTime(nTime, true))
if os.time() == 5.0 then
redstone.setOuput("back", false)
elseif os.time() == 18.0 then
redstone.setOutput("back", true)
end
sleep(1)
end
libraryaddict #2
Posted 16 April 2012 - 11:30 AM



while true do
shell.run("clear")
local nTime = os.time()
print( "Time: "..textutils.formatTime(nTime, true))
if math.floor(os.time()) == 5.0 then
redstone.setOuput("back", false)
elseif math.floor(os.time()) == 18.0 then
redstone.setOutput("back", true)
end
sleep(1)
end
Try that.
math.floor() rounds it down to the nearest whole number
slayerdwb #3
Posted 16 April 2012 - 12:18 PM
Thank you so much, program works flawlessly now.