Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- width = 10
- length = 20
- height = 5
- moves = 0
- dir = "N"
- pos.x = 0
- pos.y = 0
- pos.z = 0
- while pos.x ~= width and pos.y ~= length and pos.z ~= height do
- turtle.dig()
- if moveForward() then
- moves = moves + 1
- if moves == width * length then
- moves = 0
- turtle.digUp()
- moveUp()
- end
- if width == pos.x then
- turnRight()
- turtle.dig()
- moveForward()
- turnRight()
- elseif pos.x == 0 then
- turnLeft()
- turtle.dig()
- moveForward()
- turnLeft()
- end
- end
- end
- function moveForward()
- if turtle.forward() then
- if dir == "E" then
- pos.x = pos.x + 1
- elseif dir == "N" then
- pos.y = pos.y + 1
- elseif dir == "S" then
- pos.y = pos.y - 1
- else
- pos.x = pos.x - 1
- return true
- end
- return false
- end
- function moveUp()
- if turtle.up() then
- pos.z = pos.z + 1
- return true
- end
- return false
- end
- function turnLeft()
- if turtle.turnLeft() then
- if dir == "E" then
- dir = "N"
- elseif dir == "N" then
- dir = "W"
- elseif dir == "S" then
- dir = "E"
- else
- dir = "W"
- end
- end
- function turnRight()
- if turtle.turnRight() then
- if dir == "E" then
- dir = "S"
- elseif dir == "N" then
- dir = "E"
- elseif dir == "S" then
- dir = "W"
- else
- dir = "N"
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement