Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Advertisement
Incomprehensible

modem testing receiver

Apr 4th, 2025 (edited)
306
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.85 KB | None | 0 0
  1. local monitor = peripheral.find("monitor")
  2. local modem = peripheral.find("modem", rednet.open) -- doing it like this finds all modem peripherals and then opens rednet on them
  3. local tPos
  4. --- MAIN
  5. monitor.clear()
  6. monitor.setCursorPos(1,1)
  7. monitor.setTextScale(0.5)
  8. monitor.write("Hello, ID: " .. os.computerID()) --the id of the computer
  9.  
  10. function vec3ToString(vec3)
  11.     local str = ("(x:" .. math.floor(vec3.x+0.5) .. ", y:" .. math.floor(vec3.y+0.5) .. ", z:" .. math.floor(vec3.z+0.5) .. ")")
  12.     return str
  13. end
  14.  
  15. function receivePosMessage()
  16.     local id, message = rednet.receive(nil,0.5)
  17.     if (message == nil) then return end
  18.     monitor.clear()
  19.     monitor.setCursorPos(1,1)
  20.     monitor.write("Message from ID: " .. id .. " = " .. vec3ToString(message))
  21.     tPos = message
  22.  
  23. end
  24.  
  25. function update()
  26.     receivePosMessage()
  27. end
  28.  
  29. while true do
  30.     sleep(0.5)
  31.     update()
  32. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement