Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local drone = component.proxy(component.list('drone')())
- local port = 43
- local modem = component.proxy(component.list('modem')())
- modem.open(port)
- local distance = 0
- local d1 = 0
- local function ping()
- while true do
- e, _, _, _, d, msg=computer.pullSignal(1)
- if e=='modem_message' and msg == 'PING' then
- distance = d
- return true
- end
- end
- end
- local function mv(dir)
- d1 = distance
- if dir == 1 then
- drone.move(1, 0, 0)
- ping()
- if d1 > distance then
- drone.move(1, 0, 0)
- else
- drone.move(-2, 0, 0)
- end
- elseif dir == 2 then
- drone.move(0, 1, 0)
- ping()
- if d1 > distance then
- drone.move(0, 1, 0)
- else
- drone.move(0, -2, 0)
- end
- elseif dir == 3 then
- drone.move(0, 0, 1)
- ping()
- if d1 > distance then
- drone.move(0, 0, 1)
- else
- drone.move(0, 0, -2)
- end
- end
- end
- ping()
- while distance > 3 do
- for i = 1, 3 do
- mv(i)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement