Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Implementation of a redstone switchboard endpoint.
- -- The client controls the actual device that is being turned on or off.
- -- The switchboard controller is responsible for setting and querying the client's state.
- -- Configuration variables.
- local sModemSide = "right"
- local sRedstoneSide = "top"
- local sName = "Spawners"
- -- State variables.
- local bOutputState = false
- -- Local variables.
- local nSenderID
- local tMessage
- print("Switchbarod endpoint initializing...")
- -- Initialize.
- rednet.open(sModemSide)
- -- Do an initial broadcast, to announce we're here.
- rednet.broadcast({Name=sName, State=bOutputState}, "switchboard")
- print("Ready.")
- -- Message loop.
- while true do
- nSenderID, tMessage = rednet.receive("switchboard")
- if tMessage.Command == "set" then
- -- Turn output on or off.
- if tMessage.State == true then
- print("Turning output on.")
- redstone.setAnalogOutput(sRedstoneSide, 15)
- bOutputState = true
- else
- print("Turning output off.")
- redstone.setAnalogOutput(sRedstoneSide, 0)
- bOutputState = false
- end
- -- Update the controller's state.
- rednet.send(nSenderID, {Name=sName, State=bOutputState}, "switchboard")
- elseif tMessage.Command == "get" then
- -- Get the current output state.
- rednet.send(nSenderID, {Name=sName, State=bOutputState}, "switchboard")
- elseif tMessage.Command == "kill" then
- -- Kills the endpoint, leaving it in it's current output state.
- print("Termination request!")
- break
- end
- end
- -- Uninitialize.
- rednet.close(sModemSide)
- print("Switchboard endpoint terminated.")
Add Comment
Please, Sign In to add comment