Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Function to dig forward and move
- function digForward()
- while turtle.detect() do
- turtle.dig()
- end
- turtle.forward()
- end
- -- Function to dig down
- function digDown()
- while turtle.detectDown() do
- turtle.digDown()
- end
- turtle.down()
- end
- -- Function to return the turtle to the starting point
- function returnToSurface(height)
- for i = 1, height do
- turtle.up()
- end
- end
- -- Function to dig a layer
- function digLayer(width)
- for i = 1, width do
- for j = 1, width - 1 do
- digForward()
- end
- if i < width then
- if i % 2 == 1 then
- turtle.turnRight()
- digForward()
- turtle.turnRight()
- else
- turtle.turnLeft()
- digForward()
- turtle.turnLeft()
- end
- end
- end
- if width % 2 == 1 then
- turtle.turnRight()
- for i = 1, width - 1 do
- turtle.forward()
- end
- turtle.turnRight()
- else
- turtle.turnLeft()
- for i = 1, width - 1 do
- turtle.forward()
- end
- turtle.turnLeft()
- end
- end
- -- Main function
- function digSquareHole(width, depth)
- for level = 1, depth do
- digLayer(width)
- if level < depth then
- digDown()
- end
- end
- returnToSurface(depth)
- end
- -- User input
- print("Enter the width of the hole:")
- local width = tonumber(read())
- print("Enter the depth of the hole:")
- local depth = tonumber(read())
- -- Execute the digging program
- digSquareHole(width, depth)
Advertisement
Add Comment
Please, Sign In to add comment