Advertisement
ksaw000

moveTo

Feb 3rd, 2021 (edited)
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. require("programs/globalVars")
  2.  
  3. function forward()
  4. CURRX,CURRY,CURRZ = gps.locate()
  5. turtle.forward()
  6. STEPS=STEPS+1
  7. end
  8.  
  9. function turnLeft()
  10. HEADING = (HEADING-1)%4
  11. turtle.turnLeft()
  12. end
  13.  
  14. function turnRight()
  15. HEADING = (HEADING+1)%4
  16. turtle.turnRight()
  17. end
  18.  
  19. function turnAround()
  20. turnRight()
  21. turnRight()
  22. end
  23.  
  24. function moveVertical(value)
  25. if value < 0 then
  26. for i=math.abs(value),1,-1 do
  27. turtle.digDown()
  28. turtle.down()
  29. STEPS=STEPS+1
  30. end
  31. else
  32. for i=value,1,-1 do
  33. turtle.digUp()
  34. turtle.up()
  35. STEPS=STEPS+1
  36. end
  37. end
  38. end
  39.  
  40. function move(value)
  41. checkFuel()
  42. for i=value,0,-1 do
  43. turtle.dig()
  44. forward()
  45. end
  46. end
  47. ------------------------------------------------------
  48. X,Y,Z=tonumber(arg[2]),tonumber(arg[3]),tonumber(arg[4])
  49.  
  50. if(CURRX == X and CURRY == Y and CURRZ == Z) then
  51. print("Already here!")
  52.  
  53. else
  54. --translate in the X direction
  55. if currX~=X then
  56. if X>currX and HEADING ~= 2 then
  57. makeHeading(2)
  58. elseif X<currX and HEADING ~=0 then
  59. makeHeading(0)
  60. end
  61. move(math.abs(X-currX))
  62. end
  63.  
  64. --translate in the Z direction
  65. if CURRZ~=Z then
  66. if Z>CURRZ and HEADING ~= 3 then
  67. makeHeading(3)
  68. elseif Z<CURRZ and HEADING ~=1 then
  69. makeHeading(1)
  70. end
  71. move(math.abs(Z-currZ))
  72. end
  73. --translate in the Y direction
  74. if CURRY~=Y then
  75. moveVertical(Y-CURRY)
  76. end
  77. print("done")
  78. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement