5

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
4

2 Answers 2

20

Looking at the Turtle API you will see the getFuelLimit() is only implemented in version 1.6, and you are running version 1.57.

From the wiki:

Added by version 1.6 of ComputerCraft, this command returns the maximum amount of fuel a turtle may store. By default, a regular turtle may hold 20,000 units, and an advanced model 100,000 units; both values can be changed in ComputerCraft.cfg.

In builds prior to 1.6, turtles may store practically unlimited amounts of fuel.

6

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .