Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Stepper: A simple program to dig stairs
- Author: Brandon Weaver (keystonelemur / baweaver)
- Notes:
- --]]
- local tArgs = { ... }
- os.loadAPI('_') -- load in underscore
- -- Distance to mine
- local height = tArgs[1] or 1
- -- Shorten the turtle name
- local t = turtle
- -- Finds the shortage of fuel for the round trip
- local function checkFuelDeficit()
- return ((2 * height) - t.getFuelLevel()) + 2
- end
- -- Confirm that we have adequate fuel for the trip
- local level = checkFuelDeficit()
- if level > 0 then
- -- Attempt to correct the deficit
- print('Insufficient fuel of'..level..' units, attempting refuel...')
- t.refuel()
- -- See if that worked, or end the program
- local newLevel = checkFuelDeficit()
- if newLevel > 0 then
- print('Cannot make trip, fuel is short by'..newLevel..' units. Goodbye')
- return
- end
- end
- local function clearForward()
- while t.detect() do
- t.dig()
- sleep(0.5) -- lag offset. Screwy gravel...
- end
- end
- -- Clear a forward path
- local function clearDown()
- t.digDown()
- clearForward()
- t.forward()
- t.digUp()
- t.digDown()
- t.down()
- end
- -- Main program loop
- _.do_times(height, function (n)
- clearDown()
- end)
Advertisement
Add Comment
Please, Sign In to add comment