Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local args = {...}
- local length = args[1]
- local depth = args[2]
- local width = args[3]
- if width == nil then
- error("Usage: dig <length> <depth> <width>")
- end
- local direction = 0
- local goRight = false
- local x, y, z = 1, 1, 1
- local function move()
- if turtle.forward() then
- if direction == 0 then
- x = x + 1
- elseif direction == 1 then
- z = z + 1
- elseif direction == 2 then
- x = x - 1
- elseif direction == 3 then
- z = z - 1
- else
- error("Direction value out of bounds")
- end
- else
- turtle.dig()
- return move()
- end
- end
- local function down()
- if turtle.down() then
- y = y + 1
- else
- turtle.digDown()
- return down()
- end
- end
- local function left()
- turtle.turnLeft()
- direction = (direction + 1) % 4
- end
- local function right()
- turtle.turnRight()
- direction = (direction - 1) % 4
- end
- -- CC might stop loops from functioning w/o the inclusion of events
- local function unlock()
- os.queueEvent("hai")
- os.pullEvent()
- end
- for i = 1, depth-1 do
- for j = 1, width-1 do
- for k = 1, length-1 do
- move()
- unlock()
- end
- if goRight then
- right()
- move()
- right()
- else
- left()
- move()
- left()
- end
- goRight = not goRight
- unlock()
- end
- down()
- left()
- left()
- goRight = not goRight
- unlock()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement