Advertisement
Guest User

Turtle

a guest
Mar 27th, 2015
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. facing = 2
  2.  
  3. function turnTo(direction)
  4. dif = facing-direction
  5. for i=1,math.abs(dif) do
  6. if dif<0 then turtle.turnRight()
  7. elseif dif>0 then turtle.turnLeft()
  8. end
  9. end
  10. facing = direction
  11. print("Facing "..facing)
  12. end
  13.  
  14. function goSide(side, count)
  15. turnTo(side)
  16. for i=1,math.abs(count) do
  17. if count>0 then turtle.forward()
  18. elseif count<0 then turtle.backward()
  19. end
  20. end
  21. end
  22.  
  23. function goUp(count)
  24. for i=1,math.abs(count) do
  25. if count>0 then turtle.up()
  26. elseif count<0 then turtle.down()
  27. end
  28. end
  29. end
  30.  
  31. function goto(x,y,z, tX,tY,tZ)
  32. dx = tX-x
  33. dy = tY-y
  34. dz = tZ-z
  35.  
  36. goUp(dy)
  37. if dx>1 then
  38. goSide(3,dx)
  39. elseif dx<-1 then
  40. goSide(1,-dx)
  41. end
  42.  
  43. if dz>1 then
  44. goSide(0, dz)
  45. elseif dz<-1 then
  46. goSide(2, -dz)
  47. end
  48. end
  49.  
  50. args = {...}
  51. x,y,z = gps.locate()
  52. goto(x,y,z, args[1], args[2], args[3])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement