Where am I going wrong with this code?

Where am I going wrong with this code? - 1 + 1 = 3 Text on Black Chalkboard

FTB Direwolf20 v 1.0.21 CC 1.57

I have a turtle mining script that I am getting an error 'attempt to call nil' on line 18:

if turtle.getFuelLevel() >= turtle.getFuelLimit() - 500 then

and cannot see what's causing it. Here's the complete code:

chestFuel = 15
fuel = 14

function CheckFuel()
if turtle.getFuelLevel() ~= 'unlimited' then
 if turtle.getItemCount(fuel) == 0 then
  turtle.select(chestFuel)
  turtle.placeUp()
  turtle.select(fuel)
  turtle.suckUp()
  turtle.digUp()
  turtle.select(1)
  end
  if turtle.getFuelLevel() < 200 then
   print('Current fuel lvl: ' .. turtle.getFuelLevel() .. ': Refueling...')
   turtle.select(fuel)
   while true do
    if turtle.getFuelLevel() >= turtle.getFuelLimit() - 500 then
     print('Fueled Up')
     break
    end
    turtle.refuel()
    print('Fuel lvl: ' .. turtle.getFuelLevel())
   end
   turtle.select(1)
  end
 end
end


Best Answer

to make it forward compatible you can do the following:

function getFuelLimit()
    if turtle.getFuelLimit ~= nil then
        return turtle.getFuelLimit()
    else
        return 0;
    end
end

and add a check for 0 when checking the fuel against it or set your own fuel limit




Pictures about "Where am I going wrong with this code?"

Where am I going wrong with this code? - Metro Train Going through City Downtown
Where am I going wrong with this code? - Man Holding an Ipad with a Message on a Yellow Background
Where am I going wrong with this code? - A Woman Showing a Placard





Frankie J and Baby Bash \




Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.

Images: George Becker, Benjamin Suter, MART PRODUCTION, olia danilevich