Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- rednet.open("right")
- local args = {...}
- if args[3] == nill then
- print("usage: " .. shell.getRunningProgram() .. " <watcherID> <side> <defaultState> [invert]")
- error()
- end
- local wid = tonumber(args[1])
- local side = args[2]
- local state = args[3]
- local invert = args[4] == "invert"
- function xor(a, b)
- return not a ~= not b
- end
- redstone.setOutput(side, xor(state == "on", invert))
- print("initial " .. state)
- rednet.send(wid, "stateplease")
- while true do
- local id, msg = rednet.receive()
- if id == wid and msg == "on" then
- redstone.setOutput(side, xor(true, invert))
- print(os.clock() .. " on")
- end
- if id == wid and msg == "off" then
- redstone.setOutput(side, xor(false, invert))
- print(os.clock() .. " off")
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment