Advertisement
psychic__panda

testit

Nov 13th, 2014
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.57 KB | None | 0 0
  1. local positionX=0
  2. local positionY=0
  3. local positionZ=0
  4. right="right"
  5. left="left"
  6. up="up"
  7. down="down"
  8. forward="forward"
  9. back="back"
  10.  
  11. function doMove(direction,distance)
  12.  
  13. -- set defaults
  14. if (distance==nil) then distance = 1 end
  15. if (distance==0) then return end
  16. direction=direction or "none"
  17.  
  18. --fix negative distances
  19. if (distance<0) then
  20. distance=distance * -1
  21. if (direction==right) then direction=left
  22. elseif (direction==left) then direction=right
  23. elseif (direction==forward) then direction=back
  24. elseif (direction==back) then direction=forward
  25. elseif (direction==up) then direction=down
  26. elseif (direction==down) then direction=up
  27. end
  28. end
  29.  
  30. -- increase or decrease position with increment
  31. if ((direction==right) or (direction==up) or (direction==forward)) then
  32. increment=1
  33. else
  34. increment=-1
  35. end
  36.  
  37. --always face forward so that suck works
  38. --set temporary location to update
  39. if (direction==right) then
  40. tmpLocation=positionX
  41. turtle.turnRight()
  42. elseif (direction==left) then
  43. tmpLocation=positionX
  44. turtle.turnLeft()
  45. elseif (direction==back) then
  46. turtle.turnLeft()
  47. turtle.turnLeft()
  48. tmpLocation=positionY
  49. elseif (direction==forward) then
  50. tmpLocation=positionY
  51. elseif ((direction==up) or (direction==down)) then
  52. tmpLocation=positionZ
  53. else
  54. print("unknown direction: "..direction)
  55. return
  56. end
  57.  
  58. --move and update position
  59. if (direction==up) then
  60. for d=1,distance do
  61. turtle.suckUp()
  62. if turtle.up() then tmpLocation=tmpLocation+increment end
  63. end
  64. elseif (direction==down) then
  65. for d=1,distance do
  66. turtle.suckDown()
  67. if turtle.down() then tmpLocation=tmpLocation+increment end
  68. end
  69. else
  70. for d=1,distance do
  71. turtle.suck()
  72. if turtle.forward() then tmpLocation=tmpLocation+increment end
  73. end
  74. end
  75.  
  76. --set the globalposition and face correct direction
  77. if (direction==right) then
  78. positionX=tmpLocation
  79. turtle.turnLeft()
  80. elseif (direction==left) then
  81. positionX=tmpLocation
  82. turtle.turnRight()
  83. elseif (direction==back) then
  84. positionY=tmpLocation
  85. turtle.turnLeft()
  86. turtle.turnLeft()
  87. elseif (direction==forward) then
  88. positionY=tmpLocation
  89. elseif ((direction==up) or (direction==down)) then
  90. positionZ=tmpLocation
  91. end
  92.  
  93.  
  94. end
  95.  
  96. print("X: "..positionX..", Y: "..positionY..", Z: "..positionZ)
  97. print(right)
  98. doMove(left,-2)
  99. sleep(2)
  100. print(left)
  101. doMove(right,-2)
  102. sleep(2)
  103. print(up)
  104. doMove(down,-2)
  105. sleep(2)
  106. print(down)
  107. doMove(up,-2)
  108. sleep(2)
  109. print(forward)
  110. doMove(back,-2)
  111. sleep(2)
  112. print(back)
  113. doMove(forward,-2)
  114. print("done")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement