Lemur

stepper.lua

Sep 10th, 2014
318
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.19 KB | None | 0 0
  1. --[[
  2. Stepper: A simple program to dig stairs
  3.  
  4. Author: Brandon Weaver (keystonelemur / baweaver)
  5.  
  6. Notes:
  7. --]]
  8.  
  9. local tArgs = { ... }
  10.  
  11. os.loadAPI('_') -- load in underscore
  12.  
  13. -- Distance to mine
  14. local height = tArgs[1] or 1
  15.  
  16. -- Shorten the turtle name
  17. local t = turtle
  18.  
  19. -- Finds the shortage of fuel for the round trip
  20. local function checkFuelDeficit()
  21.   return ((2 * height) - t.getFuelLevel()) + 2
  22. end
  23.  
  24. -- Confirm that we have adequate fuel for the trip
  25. local level = checkFuelDeficit()
  26. if level > 0 then
  27.   -- Attempt to correct the deficit
  28.   print('Insufficient fuel of'..level..' units, attempting refuel...')
  29.   t.refuel()
  30.  
  31.   -- See if that worked, or end the program
  32.   local newLevel = checkFuelDeficit()
  33.   if newLevel > 0 then
  34.     print('Cannot make trip, fuel is short by'..newLevel..' units. Goodbye')
  35.     return
  36.   end
  37. end
  38.  
  39. local function clearForward()
  40.   while t.detect() do
  41.     t.dig()
  42.     sleep(0.5) -- lag offset. Screwy gravel...
  43.   end
  44. end
  45.  
  46. -- Clear a forward path
  47. local function clearDown()
  48.   t.digDown()
  49.   clearForward()
  50.   t.forward()
  51.   t.digUp()
  52.   t.digDown()
  53.   t.down()
  54. end
  55.  
  56. -- Main program loop
  57. _.do_times(height, function (n)
  58.   clearDown()
  59. end)
Advertisement
Add Comment
Please, Sign In to add comment