fishermedders

Fisher Rednet Protocol

Feb 18th, 2017
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --Fisher Rednet Protocol
  2. --Made by Fisher Medders - FisherMedders.com
  3. --Free of use but do give credit.
  4. --Started on 2/18/17 - In a hotel for SEWE 2017
  5.  
  6. function deargify( tArgs )
  7.   sArgs = ""
  8.   for i = 1, #tArgs-1 do
  9.     sArgs = sArgs..tArgs[i]..":"
  10.   end
  11.   sArgs = sArgs..tArgs[#tArgs]
  12.   return sArgs
  13. end
  14.    
  15. function argify( sArgs )
  16.   tArgs = {}
  17.   for sArg in string.gmatch( sArgs, '([^:]+)' ) do
  18.     table.insert( tArgs, sArg )
  19.   end
  20.   return tArgs
  21. end
  22.  
  23. function receive( sProtocol, nTimeout )
  24.   if nTimeout == nil then
  25.     evnt = {os.pullEvent( "rednet_message" )}
  26.     if string.find( evnt[3], sProtocol..":" ) then
  27.       tArgs = argify( evnt[3] )
  28.     end
  29.   else
  30.     if tonumber( nTimeout ) then
  31.       evnt = {rednet.receive()}
  32.       tArgs = argify( evnt[2] )
  33.     else
  34.       error("Receive was not nil, was also not a number.")
  35.     end
  36.   end
  37.   return tArgs
  38. end
  39.  
  40. function send( nId, tArgs )
  41.   rednet.send( nId, deargify( tArgs ) )
  42. end
  43.  
  44. function broadcast( tArgs )
  45.   rednet.broadcast( deargify( tArgs ) )
  46. end
Add Comment
Please, Sign In to add comment