Olyvia

relay but fixed

Aug 6th, 2025 (edited)
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.95 KB | None | 0 0
  1. local sides = {
  2.   minium = { side = "left", color = colors.red },
  3.   blaze = { side = "back", color = colors.orange },
  4. }
  5.  
  6. local modemSide = "top"
  7. rednet.open(modemSide)
  8. print("Relay online. Awaiting commands...")
  9.  
  10. while true do
  11.   local senderId, message = rednet.receive()
  12.   print("Received command from ID:", senderId, "-", message)
  13.   local device, state = message:match("^(%S+)%s+(%S+)$")
  14.   if device and state then
  15.     local info = sides[device:lower()]
  16.     if info then
  17.       local side = info.side
  18.       local color = info.color
  19.       local current = rs.getBundledOutput(side)
  20.       if state == "on" then
  21.         rs.setBundledOutput(side, bit.bor(current, color))
  22.       elseif state == "off" then
  23.         rs.setBundledOutput(side, bit.band(current, bit.bnot(color)))
  24.       else
  25.         print("Invalid state:", state)
  26.       end
  27.     else
  28.       print("Unknown device:", device)
  29.     end
  30.   else
  31.     print("Malformed command.")
  32.   end
  33. end
  34.  
Advertisement
Add Comment
Please, Sign In to add comment