mythicmaniac

Untitled

Jan 23rd, 2021
829
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ops = {
  2.     "forward",
  3.     "t-right",
  4.     "forward",
  5.     "forward",
  6.     "forward",
  7.     "up",
  8.     "t-left",
  9.     "t-left",
  10.     "forward",
  11.     "forward",
  12.     "forward",
  13.     "down",
  14.     "t-right",
  15. }
  16.  
  17.  
  18. function checkFuel()
  19.     local fuelAmount = turtle.getFuelLevel()
  20.     if (fuelAmount < 20) then
  21.         write("Attempting to refuel")
  22.         local refuelSuccess = turtle.refuel(1)
  23.         if (refuelSuccess) then
  24.             write("Refuel success")
  25.         else
  26.             write("Refuel failed")
  27.         end
  28.     end
  29.     return fuelAmount > 0
  30. end
  31.  
  32. function executeOp(op)
  33.     local fuelOk = checkFuel()
  34.     if not(fuelOk) then
  35.         write("Turtle out of fuel")
  36.         return false
  37.     end
  38.     write("Executing "..op.."\n")
  39.  
  40.     if op == "forward" then
  41.         turtle.dig()
  42.         if not(turtle.forward()) then
  43.             return false
  44.         end
  45.     elseif op == "up" then
  46.         turtle.digUp()
  47.         if not(turtle.up()) then
  48.             return false
  49.         end
  50.     elseif op == "down" then
  51.         turtle.digDown()
  52.         if not(turtle.down()) then
  53.             return false
  54.         end
  55.     elseif op == "t-right" then
  56.         if not(turtle.turnRight()) then
  57.             return false
  58.         end
  59.     elseif op == "t-left" then
  60.         if not(turtle.turnLeft()) then
  61.             return false
  62.         end
  63.     else
  64.         write("Unknown op: "..op.."\n")
  65.         return false
  66.     end
  67.     return true
  68. end
  69.  
  70.  
  71. function executeSequence(sequence)
  72.     for key, op in pairs(sequence) do
  73.         if not(executeOp(op)) then
  74.             write("Problem occurred, stopping sequence")
  75.             return false
  76.         end
  77.     end
  78.     return true
  79. end
  80.  
  81. local result = executeSequence(ops)
  82. write("Exited with status: "..tostring(result).."\n")
  83.  
RAW Paste Data