Advertisement
Guest User

Untitled

a guest
Jun 14th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. --Usercode Environment
  2. local env = {}
  3.  
  4. env.pos = {0,0,0}
  5. function env.offset()
  6. drone.setStatusText(tostring(drone.getOffset()))
  7. return drone.getOffset()
  8. end
  9. function env.move(x,y,z)
  10. drone.move(x,y,z)
  11. coroutine.yield("cd", "return offset() < .05")
  12. env.pos[1] = env.pos[1] + x
  13. env.pos[2] = env.pos[2] + y
  14. env.pos[3] = env.pos[3] + z
  15. end
  16.  
  17. function env.goTo(x,y,z)
  18. env.move(x-env.pos[1],y-env.pos[2],z-env.pos[3])
  19. end
  20.  
  21. --Main Code
  22. local running = true
  23. local paused = false
  24. local condition = ""
  25.  
  26. local userCode = "move(0,10,0) move(10,-10,0) move(-10,0,0)"
  27.  
  28. function mainRoutine()
  29. computer.beep(1000,1)
  30. load(userCode, env)()
  31. --running = false
  32. end
  33.  
  34. local main = coroutine.create(mainRoutine)
  35.  
  36. while running do
  37. --currentSignal = {computer.pullSignal(0)}
  38. if not paused then
  39. local y, c = coroutine.resume(main)
  40. if y == "cd" then
  41. paused = true
  42. condition = c
  43. end
  44. else
  45. if load(condition, env)() then
  46. paused = false
  47. end
  48. end
  49. computer.pullSignal(.2)
  50. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement