Advertisement
feedmecookies

Rednet Listener

Mar 13th, 2022
19
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. -- rednet listener --
  2.  
  3. rednet.open("front") -- side of the modem
  4. m = peripheral.wrap("top") -- where the monitor is.
  5. widht, height = m.getSize()
  6.  
  7.  
  8. m.setTextScale(1) -- size of the text on screen
  9. msgAmount = height / m.getTextScale() -- the amount of messages displayed scale according to monitor size and text size, does not take into account size of string
  10.  
  11.  
  12.  
  13. whitelist = {} -- ids to listen for
  14. messages = {} -- list of messages that are going to be displayed.
  15.  
  16.  
  17.  
  18. ---------------------
  19.  
  20. while true do
  21.  
  22.  
  23. event, id, msg, distance = os.pullEvent("rednet_message")
  24.  
  25. for i = 1, #whitelist do
  26. if id == whitelist[i] then
  27. table.insert(messages, msg)
  28. end
  29.  
  30. if #messages > msgAmount then
  31.  
  32. table.remove(messages,1)
  33.  
  34. end
  35. m.clear()
  36. for i = 1, #messages do
  37. m.setCursorPos(1,i)
  38. m.write(messages[i])
  39. end
  40.  
  41.  
  42.  
  43. end
  44.  
  45.  
  46.  
  47.  
  48. end
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement