Take the 2-minute tour ×
Arqade is a question and answer site for passionate videogamers on all platforms. It's 100% free, no registration required.

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
share|improve this question
1  
Relevant meta - meta.gaming.stackexchange.com/questions/7661/… –  shanodin Apr 29 at 6:11
1  
Hve you declared the fonction getFuelLimit ? What does it look like ? –  WizLiz Apr 29 at 6:32
1  
@wizliz getFuelLimit is a function in the turtle api. –  Unionhawk Apr 29 at 6:42
2  
You will have a better shot at an answer actually helping you solve this problem on Stack Overflow. –  scenia Apr 29 at 7:49

2 Answers 2

up vote 20 down vote accepted

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.

share|improve this 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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.