local args = { ... }
if #args ~= 1 then
	print( "Usage: stairs <length> [torch_interval]" )
	return
end

length = tonumber(args[1])
torch_interval = tonumber(args[2]) or 5

print('Making stairs '..length..' deep...')
print('Please add stairs at slot 1, filler blocks at slot 2 and torches at slot 3.')
print('Press any key to continue')
while true do
    event = os.pullEvent()
    if event == "key" then break end
end

function step(place_torch)
    tx.forward()
    tx.up()
    tx.down()
    if place_torch then
        turtle.select(3)
        tx.placeUp()
    end
    tx.down()
    tx.down()
    tx.down()
    tx.up()
    turtle.select(2)
    turtle.placeDown()
    tx.up()
    tx.left()
    tx.left()
    turtle.select(1)
    turtle.placeDown()
    tx.right()
    tx.right()
end

prev_mode = tx.state.move_mode 
tx.state.move_mode = 'dig'

if not turtle.compareDown(1) then
    tx.up()
end

for i=1,length do
    step(torch_interval ~= -1 and i % torch_interval == 1)
end

tx.forward()
turtle.digDown()
turtle.digUp()

tx.state.move_mode = prev_mode