gravitowl

BetterNet

Feb 1st, 2021 (edited)
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. -- BetterNet API for better wireless networking
  2. -- Free to use by everybody
  3.  
  4. ---- Variables
  5. local modem = "top"
  6. local listeners = {}
  7.  
  8. ---- Functions
  9.  
  10. -- openConnection() opens a connection.
  11.  
  12. function openConnection(modem)
  13. modem = modem
  14. rednet.open(modem)
  15. end
  16.  
  17. -- listen() listens for any messages coming in, this blocks code from running.
  18.  
  19. function listen(protocol)
  20. senderID, message = rednet.receive(protocol)
  21. if (type(message[1]) == table) then
  22. if (listeners[message[1]]) then
  23. listeners[message[1]]()
  24. end
  25. end
  26. end
  27.  
  28. -- get() specifies a function that needs to be ran if a certain message was sent.
  29.  
  30. function get(message, functionToRun)
  31. listeners[message] = functionToRun
  32. end
Add Comment
Please, Sign In to add comment