Advertisement
Guest User

drone2.lua

a guest
Jun 23rd, 2018
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.14 KB | None | 0 0
  1. local drone = component.proxy(component.list("drone")())
  2. local m=component.proxy(component.list("modem")())
  3. m.open(2412)
  4.  
  5. local function sleep(timeout)
  6.     checkArg(1, timeout, "number", "nil")
  7.     local deadline = computer.uptime() + (timeout or 0)
  8.     repeat
  9.         computer.pullSignal(deadline - computer.uptime())
  10.     until computer.uptime() >= deadline
  11. end
  12.  
  13. local function receive()
  14.   while true do
  15.  
  16.     local evt,_,_,_,_,cmd=computer.pullSignal()
  17.  
  18.     if cmd=="up" then drone.move(0, 1, 0) end
  19.     if cmd=="down" then drone.move(0, -1, 0) end
  20.     if cmd=="blue" then drone.setLightColor(0x0000ff) end
  21.     if cmd=="go" then drone.setLightColor(0x0000ff)
  22.     sleep(5)
  23.     drone.move(0, 23, 0)
  24.     sleep(3)
  25.     drone.move(-115, 0, 93)
  26.     sleep(15)
  27.     drone.move(0, -27, 0)
  28.     sleep(3)
  29.     drone.setLightColor(0x00ff2b)
  30.     sleep(20)
  31.     drone.move(0, 27, 0)
  32.     sleep(3)
  33.     drone.move(115, 0, -93)
  34.     sleep(15)
  35.     drone.move(0, -23, 0) end
  36.   end
  37. end
  38. while true do
  39.  
  40.   local result,reason=pcall(function()
  41.  
  42.     local result,reason=receive()
  43.  
  44.     if not result then return respond() end
  45.  
  46.     respond(result())
  47.  
  48.   end)
  49.  
  50.   if not result then respond() end
  51.  
  52. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement