Advertisement
remie92

Lib-Network

Feb 25th, 2024 (edited)
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.72 KB | None | 0 0
  1. local func = {}
  2.  
  3. protocol="noProtocol"
  4.  
  5. function func.enableNet()
  6.     peripheral.find("modem", rednet.open)
  7. end
  8.  
  9. function func.disableNet()
  10.     peripheral.find("modem", rednet.close)
  11. end
  12.  
  13.  
  14. function func.setProtocol(newProt)
  15.     protocol=newProt
  16. end
  17.  
  18.  
  19.  
  20. function func.sendMessage(text)
  21.     return rednet.broadcast(tostring(text),protocol)
  22. end
  23.  
  24. --sendMessage("WOW")
  25.  
  26. function func.sendMessageId(id,text)
  27.     return rednet.send(tonumber(id),tostring(text),protocol)
  28. end
  29.  
  30. --sendMessageId(1,"WOW")
  31.  
  32.  
  33. --timeout in seconds, returns nil if no message was send
  34. function func.receiveMessage(timeout)
  35.     return rednet.receive(protocol,tonumber(timeout))
  36. end
  37. --local id,data=receiveMessage(10)
  38.  
  39.  
  40.  
  41.  
  42.  
  43. return func
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement