SHOW:
|
|
- or go back to the newest paste.
| 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 receive( protocol, timeout ) |
| 6 | + | function deargify( tArgs ) |
| 7 | - | if timeout == nil then |
| 7 | + | sArgs = "" |
| 8 | for i = 1, #tArgs-1 do | |
| 9 | - | if string.find( evnt[3], protocol..":" ) then |
| 9 | + | sArgs = sArgs..tArgs[i]..":" |
| 10 | - | args = argify( evnt[3] ) |
| 10 | + | |
| 11 | sArgs = sArgs..tArgs[#tArgs] | |
| 12 | return sArgs | |
| 13 | - | if tonumber( timeout ) then |
| 13 | + | |
| 14 | ||
| 15 | - | args = argify( evnt[2] ) |
| 15 | + | function argify( sArgs ) |
| 16 | tArgs = {}
| |
| 17 | for sArg in string.gmatch( sArgs, '([^:]+)' ) do | |
| 18 | table.insert( tArgs, sArg ) | |
| 19 | end | |
| 20 | - | return args |
| 20 | + | return tArgs |
| 21 | end | |
| 22 | - | |
| 22 | + | |
| 23 | - | function argify( argstr ) |
| 23 | + | function receive( sProtocol, nTimeout ) |
| 24 | - | args = {}
|
| 24 | + | if nTimeout == nil then |
| 25 | - | for arg in string.gmatch( evnt[3], '([^:]+)' ) do |
| 25 | + | |
| 26 | - | table.insert( args, arg ) |
| 26 | + | if string.find( evnt[3], sProtocol..":" ) then |
| 27 | tArgs = argify( evnt[3] ) | |
| 28 | - | return args |
| 28 | + | |
| 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 |