Advertisement
aharries

Receiver 3.0.7

Apr 17th, 2024
696
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.95 KB | None | 0 0
  1. -- Receiver Program for Quarry Turtle
  2. -- Usage: startup <monitor_side> <modem_side>
  3. local args = {...}
  4.  
  5. if #args < 2 then
  6.     print("Usage: startup <monitor_side> <modem_side>")
  7.     return
  8. end
  9.  
  10. local monitorSide = args[1]
  11. local modemSide = args[2]
  12. local monitor = peripheral.wrap(monitorSide)
  13. local modem = peripheral.wrap(modemSide)
  14.  
  15. if not monitor or not modem then
  16.     print("Error: Make sure you have the monitor and modem correctly connected.")
  17.     return
  18. end
  19.  
  20. rednet.open(modemSide)
  21.  
  22. -- Function to handle incoming data
  23. local function handleData(senderId, message, protocol)
  24.     monitor.clear()
  25.     monitor.setCursorPos(1, 1)
  26.     monitor.write("Data from Turtle ID " .. senderId .. ": " .. message)
  27. end
  28.  
  29. -- Main loop to receive messages
  30. local function main()
  31.     while true do
  32.         local senderId, message, protocol = rednet.receive()
  33.         handleData(senderId, message, protocol)
  34.     end
  35. end
  36.  
  37. -- Run the main function
  38. main()
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement