Advertisement
Guest User

Untitled

a guest
Nov 28th, 2015
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. width = 10
  2. length = 20
  3. height = 5
  4.  
  5. moves = 0
  6.  
  7. dir = "N"
  8. pos.x = 0
  9. pos.y = 0
  10. pos.z = 0
  11.  
  12. while pos.x ~= width and pos.y ~= length and pos.z ~= height do
  13.  
  14. turtle.dig()
  15.  
  16. if moveForward() then
  17. moves = moves + 1
  18.  
  19. if moves == width * length then
  20. moves = 0
  21. turtle.digUp()
  22. moveUp()
  23. end
  24.  
  25. if width == pos.x then
  26. turnRight()
  27. turtle.dig()
  28. moveForward()
  29. turnRight()
  30. elseif pos.x == 0 then
  31. turnLeft()
  32. turtle.dig()
  33. moveForward()
  34. turnLeft()
  35. end
  36.  
  37. end
  38.  
  39. end
  40.  
  41.  
  42. function moveForward()
  43. if turtle.forward() then
  44.  
  45. if dir == "E" then
  46. pos.x = pos.x + 1
  47. elseif dir == "N" then
  48. pos.y = pos.y + 1
  49. elseif dir == "S" then
  50. pos.y = pos.y - 1
  51. else
  52. pos.x = pos.x - 1
  53.  
  54. return true
  55. end
  56.  
  57. return false
  58. end
  59.  
  60.  
  61. function moveUp()
  62. if turtle.up() then
  63. pos.z = pos.z + 1
  64. return true
  65. end
  66.  
  67. return false
  68. end
  69.  
  70.  
  71. function turnLeft()
  72. if turtle.turnLeft() then
  73. if dir == "E" then
  74. dir = "N"
  75. elseif dir == "N" then
  76. dir = "W"
  77. elseif dir == "S" then
  78. dir = "E"
  79. else
  80. dir = "W"
  81. end
  82. end
  83.  
  84. function turnRight()
  85. if turtle.turnRight() then
  86. if dir == "E" then
  87. dir = "S"
  88. elseif dir == "N" then
  89. dir = "E"
  90. elseif dir == "S" then
  91. dir = "W"
  92. else
  93. dir = "N"
  94. end
  95. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement