Advertisement
melzneni

Turti Lib Rednet

Sep 16th, 2023 (edited)
989
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.03 KB | None | 0 0
  1. local api = {}
  2.  
  3. local function openRednet()
  4.     local side
  5.     peripheral.find("modem", function(name, modem)
  6.         if modem.isWireless() then
  7.             side = name
  8.         end
  9.     end)
  10.     if not rednet.isOpen(side) then
  11.         rednet.open(side)
  12.     end
  13. end
  14.  
  15. api.broadcastRednet = {
  16.     pars = { 1, 2 },
  17.     fct = function(message, protocol)
  18.         openRednet()
  19.         rednet.broadcast(getTableSaveText({ data = message }), protocol)
  20.     end
  21. }
  22.  
  23. api.sendRednet = {
  24.     pars = { 2, 3 },
  25.     fct = function(recipient, message, protocol)
  26.         openRednet()
  27.         return rednet.send(recipient, getTableSaveText({ data = message }), protocol)
  28.     end
  29. }
  30.  
  31. api.receiveRednet = {
  32.     pars = { 0, 2 },
  33.     fct = function(protocol, timeout)
  34.         openRednet()
  35.         local id, message = rednet.receive(protocol, timeout)
  36.         if id == nil then
  37.             return { nil, nil }
  38.         end
  39.         return { id, getTableFromSaveText(message).data }
  40.     end
  41. }
  42.  
  43. return {
  44.     name = "rednet",
  45.     api = api
  46. }
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement