This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
MistrF8's profile picture

Turtle refuel program is not displaying/refueling the correct amount

Started by MistrF8, 22 January 2016 - 02:20 AM
MistrF8 #1
Posted 22 January 2016 - 03:20 AM
Hello, I'm new to computercraft and coding and I would appreciate it if I could please get some help with this program I have been writing.
This program is a WIP program for refueling using a fuel source from another minecraft mod, which is the lava crystal from awayoftime's blood magic mod. What is supposed to happen is that the turtle will extract the exact amount of fuel the user wants (10 times the amount of "cycles' the user specifies). The program is also supposed to inform you of the amount of fuel you have added to the turtle, and the new total amount of fuel in the turtle.

The problem is, the program consistently seems to refuel for 10 more points of fuel than it should. I know I am making some stupid mistake in the code, but I cannot identify what it is or how I can fix it.

select(1) -- slot 1 is where you put the lava crystal
local fuel
print("Lava Crystals grant 10 FP per cycle.")
term.write("How many refuel cycles do you want? ")
fuel = read()

for x = 0, fuel do
   turtle.refuel() --supposed to refuel the specified amount, e.g. if you wrote 10, the turtle would refuel 10 times, giving you 100 fuel points.
end
print(10*fuel.." Fuel Points were added.")
print("This TURTLE now has "..turtle.getFuelLevel().." FP in total.") --tells the user how much fuel has been added and the current total amount of fuel

I would like to note that I doubt that there is anything wrong with the lava crystal, as it consistently refuels for 10 points of fuel each time I refuel it normally (using the 'refuel' program).
Bomb Bloke #2
Posted 22 January 2016 - 03:22 AM
Give this a try, you'll see the problem:

for i = 0, 10 do
  print(i)
end
MistrF8 #3
Posted 22 January 2016 - 03:35 AM
Thank you! :)/> I tried
 for x = 0, fuel - 1 do 
instead of
 for x=0, fuel do
and it refueled for the correct amount.