Advertisement
Doob

gohome

Jul 9th, 2015
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.97 KB | None | 0 0
  1. local drone = component.proxy(component.list('drone')())
  2. local port = 43
  3. local modem = component.proxy(component.list('modem')())
  4. modem.open(port)
  5.  
  6. local distance = 0
  7. local d1 = 0
  8.  
  9. local function ping()
  10.   while true do
  11.     e, _, _, _, d, msg=computer.pullSignal(1)
  12.     if e=='modem_message' and msg == 'PING' then
  13.       distance = d
  14.       return true
  15.     end
  16.   end
  17. end
  18.  
  19. local function mv(dir)
  20.   d1 = distance
  21.   if dir == 1 then
  22.     drone.move(1, 0, 0)
  23.     ping()
  24.     if d1 > distance then
  25.       drone.move(1, 0, 0)
  26.     else
  27.       drone.move(-2, 0, 0)
  28.     end
  29.   elseif dir == 2 then
  30.     drone.move(0, 1, 0)
  31.     ping()
  32.     if d1 > distance then
  33.       drone.move(0, 1, 0)
  34.     else
  35.       drone.move(0, -2, 0)
  36.     end
  37.   elseif dir == 3 then
  38.     drone.move(0, 0, 1)
  39.     ping()
  40.     if d1 > distance then
  41.       drone.move(0, 0, 1)
  42.     else
  43.       drone.move(0, 0, -2)
  44.     end
  45.   end
  46. end
  47.  
  48. ping()
  49.  
  50. while distance > 3 do
  51.   for i = 1, 3 do
  52.     mv(i)
  53.   end
  54. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement