Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Usercode Environment
- local env = {}
- env.pos = {0,0,0}
- function env.offset()
- drone.setStatusText(tostring(drone.getOffset()))
- return drone.getOffset()
- end
- function env.move(x,y,z)
- drone.move(x,y,z)
- coroutine.yield("cd", "return offset() < .05")
- env.pos[1] = env.pos[1] + x
- env.pos[2] = env.pos[2] + y
- env.pos[3] = env.pos[3] + z
- end
- function env.goTo(x,y,z)
- env.move(x-env.pos[1],y-env.pos[2],z-env.pos[3])
- end
- --Main Code
- local running = true
- local paused = false
- local condition = ""
- local userCode = "move(0,10,0) move(10,-10,0) move(-10,0,0)"
- function mainRoutine()
- computer.beep(1000,1)
- load(userCode, env)()
- --running = false
- end
- local main = coroutine.create(mainRoutine)
- while running do
- --currentSignal = {computer.pullSignal(0)}
- if not paused then
- local y, c = coroutine.resume(main)
- if y == "cd" then
- paused = true
- condition = c
- end
- else
- if load(condition, env)() then
- paused = false
- end
- end
- computer.pullSignal(.2)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement