mythicmaniac

Untitled

Jan 23rd, 2021
741
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.     end
  64.     return true
  65. end
  66.  
  67.  
  68. function executeSequence(sequence)
  69.     for key, op in pairs(sequence) do
  70.         if not(executeOp) then
  71.             write("Problem occurred, stopping sequence")
  72.             return false
  73.         end
  74.     end
  75.     return true
  76. end
  77.  
  78. local result = executeSequence(ops)
  79. write("Exited with status: "..tostring(result))
  80.  
RAW Paste Data