Posted 09 May 2017 - 03:02 AM
I put together code a long (long) time ago and I forgot to post it. Perhaps somebody will find it helpful. I made this because I was using computers as redstone timers (for a reason I don't remember) and this code gave me a method of setting a timer up that continued to run after chunk loads/unloads.
The code basically allows you to set a computer to pulse a side at a specified interval, saves these values and loads them up on a reboot.
https://pastebin.com/ZPEgVjmx
The code basically allows you to set a computer to pulse a side at a specified interval, saves these values and loads them up on a reboot.
https://pastebin.com/ZPEgVjmx
Spoiler
local tArgs = {...}
local program = shell.getRunningProgram()
os.setComputerLabel("pulser")
if fs.exists("pulseLog") then
h = fs.open("pulseLog", "r")
log = textutils.unserialize(h.readAll())
h.close()
sSide = log[1]
duration = log[2]
sInterval = tonumber(duration)/2
else
if not tArgs[1] then
print("Set parameters: <side> <pulse interval>")
return
end
sSide = tArgs[1]
duration = tArgs[2]
sInterval = tonumber(duration)/2
h = fs.open("pulseLog", "w")
h.write(textutils.serialize(tArgs))
h.close()
h = fs.open("startup", "w")
h.write("shell.run(\""..program.."\")")
h.close()
end
while true do
term.clear()
term.setCursorPos(1,1)
print("Pulsing "..sSide.." every "..duration.." seconds.")
rs.setOutput(sSide, true)
sleep(sInterval)
rs.setOutput(sSide, false)
sleep(sInterval)
end
Edited on 09 May 2017 - 01:03 AM