Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local sides = {
- minium = { side = "left", color = colors.red },
- blaze = { side = "back", color = colors.orange },
- }
- local modemSide = "top"
- rednet.open(modemSide)
- print("Relay online. Awaiting commands...")
- while true do
- local senderId, message = rednet.receive()
- print("Received command from ID:", senderId, "-", message)
- local device, state = message:match("^(%S+)%s+(%S+)$")
- if device and state then
- local info = sides[device:lower()]
- if info then
- local side = info.side
- local color = info.color
- local current = rs.getBundledOutput(side)
- if state == "on" then
- rs.setBundledOutput(side, bit.bor(current, color))
- elseif state == "off" then
- rs.setBundledOutput(side, bit.band(current, bit.bnot(color)))
- else
- print("Invalid state:", state)
- end
- else
- print("Unknown device:", device)
- end
- else
- print("Malformed command.")
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment