xXm0dzXx

Redpos Send & Receive

Jun 25th, 2012
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.75 KB | None | 0 0
  1. rednet.open("top")
  2. x, y, z = gps.locate(2, false)
  3.  
  4. function send(x1, y1, z1, message)
  5.     return rednet.broadcast(x1.. ":(@!#!):" ..y1.. ":(@!#!):" ..z1.. ":(@!#!):" ..message)
  6. end
  7.  
  8. function receive( nTimeout )
  9.     local timer = nil
  10.     if nTimeout then
  11.         timer = os.startTimer( nTimeout )
  12.     end
  13.     while true do
  14.         local e, p1, p2, p3 = os.pullEvent()
  15.         if e == "rednet_message" then
  16.             local tWords = {}
  17.             for match in string.gmatch(p2, "[^:(@!#!):\t]+") do
  18.                 table.insert( tWords, match )
  19.             end
  20.            
  21.             if(not tWords[4] == nil)then
  22.                 if(tWords[1] == x and tWords[2] == y and tWords[3] == z)then
  23.                     return tWords[1], tWords[2], tWords[3], tWords[4]
  24.                 end
  25.             end
  26.         elseif e == "timer" and p1 == timer then
  27.             return nil, nil, nil
  28.         end
  29.     end
  30. end
Advertisement
Add Comment
Please, Sign In to add comment