Advertisement
Guest User

Untitled

a guest
Dec 5th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. --TurtleNav v0.1
  2. x = 0 --l&r z
  3. z = 0 --f&b |
  4. y = 0 --u&d y--x
  5. direction = 1
  6.  
  7.  
  8.  
  9. function orient(dir)
  10. dif = direction-dir
  11. if (dif == -1) or (dif == 3) then
  12. turtle.turnRight()
  13. elseif (dif == -2) or (dif == 2) then
  14. turtle.turnRight()
  15. turtle.turnRight()
  16. elseif (dif == -3) or (dif == 1) then
  17. turtle.turnLeft()
  18. end
  19. direction = dir
  20.  
  21. if debug == true then
  22. print("Difference = "..dif)
  23. end
  24. end
  25.  
  26. function forward()
  27. repeat
  28. until turtle.forward() == true
  29. if direction == 1 then
  30. z = z+1
  31. elseif direction == 2 then
  32. x = x+1
  33. elseif direction == 3 then
  34. z = z-1
  35. elseif direction == 4 then
  36. x = x-1
  37. end
  38. end
  39.  
  40. function back()
  41. repeat
  42. until turtle.back() == true
  43. if direction == 1 then
  44. z = z-1
  45. elseif direction == 2 then
  46. x = x-1
  47. elseif direction == 3 then
  48. z = z+1
  49. elseif direction == 4 then
  50. x = x+1
  51. end
  52. end
  53.  
  54. function up()
  55. repeat
  56. until turtle.up() == true
  57. y = y+1
  58. end
  59.  
  60. function down()
  61. repeat
  62. until turtle.down() == true
  63. y = y-1
  64. end
  65.  
  66. function travel(dX,dZ,dY)
  67. if dX > x then
  68. orient(2)
  69. elseif dX < x then
  70. orient(4)
  71. end
  72. for i = 0,math.abs(dX-x),1 do
  73. forward()
  74. end
  75.  
  76. if dZ > z then
  77. orient(1)
  78. elseif dZ < z then
  79. orient(3)
  80. end
  81. for i = 0,math.abs(dZ-z),1 do
  82. forward()
  83. end
  84.  
  85. if dY > y then
  86. for i = 0,math.abs(dY-y),1 do
  87. up()
  88. end
  89. elseif dY < y then
  90. for i = 0,math.abs(dY-y),1 do
  91. down()
  92. end
  93. end
  94. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement