Difference between revisions of "Turtle.refuel"
SuicidalSTDz (Talk | contribs) m (Added a command-line example of turtle.refuel since users are clueless about it's existance) |
(Clarifying the consumption of fuel, and adding a note about loosing fuel.) |
||
(7 intermediate revisions by 5 users not shown) | |||
Line 2: | Line 2: | ||
{{Function | {{Function | ||
|name=turtle.refuel | |name=turtle.refuel | ||
− | |args= | + | |args={{type|number}} fuel item consume quantity (optional) |
|api=turtle | |api=turtle | ||
− | |returns= | + | |returns={{type|boolean}} true if fueled, else false. |
|addon=ComputerCraft | |addon=ComputerCraft | ||
− | |desc= | + | |desc=If the currently selected slot contains [[#Fuel_Values|fuel]] items, it will consume them to give the [[turtle]] the ability to move. If the current slot doesn't contain fuel items, it returns false. If a quantity is specified, it will refuel only up to that many items. If the avaiable items quantity is lower than the specified, only the avaiable quantity will be consumed, because it can't consume what doesn't exist. If no quantity is specified, it will consume all the items in the slot. Turtles loose all the fuel when broken if they don't have a [[label]].<br><br> |
+ | |||
+ | As of ComputerCraft 1.6, turtles may no longer store practically unlimited amounts of fuel. Attempting to refuel past a given turtle's [[Turtle.getFuelLimit|limit]] with this command will destroy the items regardless, but fails to raise the fuel level higher than maximum and returns no error.<br><br> | ||
+ | |||
+ | See also: [[Turtle.getFuelLevel|turtle.getFuelLevel()]], [[Turtle.getFuelLimit|turtle.getFuelLimit()]] | ||
|examples= | |examples= | ||
{{Example | {{Example | ||
− | |desc= | + | |desc=Checks if the item in the current slot can be used as fuel without consuming it |
− | |code=turtle.refuel( | + | |code=local valid = turtle.refuel(0) |
− | |output= | + | print(valid) |
+ | |output=If the current slot is valid fuel | ||
}} | }} | ||
{{Example | {{Example | ||
− | |desc= | + | |desc=Consumes only 4 items in the current slot if the item is a valid fuel |
− | |code=refuel | + | |code=local success = turtle.refuel(4) |
− | |output= | + | print(success) |
+ | |output=whether it successfully refuelled | ||
+ | }} | ||
+ | {{Example | ||
+ | |desc=Loops through the turtle's inventory checking if the item is valid fuel and then consuming half of the stack when it is | ||
+ | |code=for i = 1, 16 do -- loop through the slots | ||
+ | turtle.select(i) -- change to the slot | ||
+ | if turtle.refuel(0) then -- if it's valid fuel | ||
+ | local halfStack = math.ceil(turtle.getItemCount(i)/2) -- work out half of the amount of fuel in the slot | ||
+ | turtle.refuel(halfStack) -- consume half the stack as fuel | ||
+ | end | ||
+ | end | ||
}} | }} | ||
}} | }} | ||
== Fuel Values == | == Fuel Values == | ||
− | Fuel values for different items. | + | Fuel values for some different items. Note that other items are accepted (including both vanilla / mod items) - generally, if an item can be used in a furnace it'll provide fuel equal to the number of items it could smelt, multiplied by ten. |
+ | |||
+ | Every movement a turtle performs consumes one fuel unit. Actions that can be performed while the turtle is stationary do not consume fuel. | ||
+ | |||
+ | Turtles can be [[ComputerCraft.cfg|configured]] to not require fuel. As of ComputerCraft 1.6, turtles may have [[Turtle.getFuelLimit|limits]] to the amount they can store at a time. | ||
{| class="wikitable sortable" | {| class="wikitable sortable" | ||
Line 56: | Line 76: | ||
| Vanilla | | Vanilla | ||
|- | |- | ||
− | | Lava | + | | [[Lava]] |
| 1000 | | 1000 | ||
| Vanilla | | Vanilla | ||
Line 98: | Line 118: | ||
Formula changed to ((fuel * 5) / 100) | Formula changed to ((fuel * 5) / 100) | ||
+ | |||
== Trivia == | == Trivia == | ||
[[Category:Lua_Core_Functions]] | [[Category:Lua_Core_Functions]] |
Latest revision as of 14:31, 21 April 2015
Function turtle.refuel | |
If the currently selected slot contains fuel items, it will consume them to give the turtle the ability to move. If the current slot doesn't contain fuel items, it returns false. If a quantity is specified, it will refuel only up to that many items. If the avaiable items quantity is lower than the specified, only the avaiable quantity will be consumed, because it can't consume what doesn't exist. If no quantity is specified, it will consume all the items in the slot. Turtles loose all the fuel when broken if they don't have a label. As of ComputerCraft 1.6, turtles may no longer store practically unlimited amounts of fuel. Attempting to refuel past a given turtle's limit with this command will destroy the items regardless, but fails to raise the fuel level higher than maximum and returns no error. | |
Syntax | turtle.refuel(number fuel item consume quantity (optional)) |
Returns | boolean true if fueled, else false. |
Part of | ComputerCraft |
API | turtle |
Examples
Example | |
Checks if the item in the current slot can be used as fuel without consuming it | |
Code |
local valid = turtle.refuel(0) print(valid) |
Output | If the current slot is valid fuel |
Example | |
Consumes only 4 items in the current slot if the item is a valid fuel | |
Code |
local success = turtle.refuel(4) print(success) |
Output | whether it successfully refuelled |
Fuel Values
Fuel values for some different items. Note that other items are accepted (including both vanilla / mod items) - generally, if an item can be used in a furnace it'll provide fuel equal to the number of items it could smelt, multiplied by ten.
Every movement a turtle performs consumes one fuel unit. Actions that can be performed while the turtle is stationary do not consume fuel.
Turtles can be configured to not require fuel. As of ComputerCraft 1.6, turtles may have limits to the amount they can store at a time.
Item | Movement gained | Added by |
---|---|---|
Biofuel Can | 520 | IndustrialCraft |
Scrap | 15 | IndustrialCraft |
Coalfuel Can | 1520 | IndustrialCraft |
Wooden Scaffolding | 15 | IndustrialCraft |
Peat | 80 | Forestry |
Sugar Cane | 0 | Vanilla |
Wooden Tools | 10 | Vanilla |
Lava | 1000 | Vanilla |
Blaze Rod | 120 | Vanilla |
Wood Blocks | 15 | Vanilla |
Sticks | 5 | Vanilla |
Coal/Charcoal | 80 | Vanilla |
Mushroom Blocks | 15 | Vanilla |
Coal Coke | 320 | Railcraft |
1.41:
The formula for calculating the movement gain from a fuel is "((fuel / 100) * 6)". Where fuel is the items burn time in ticks in a regular furnace and "/" is integer division.
1.42+:
Formula changed to ((fuel * 6) / 100). This will give more accurate movement values.
1.48:
Formula changed to ((fuel * 5) / 100)