2 posts
Posted 12 November 2012 - 11:36 AM
I'm trying to write my own mining program, and I want the turtle to return to the surface if the fuel level falls below a certain level. How would I have it check the fuel level in a loop, and then affect an if/then statement?
68 posts
Posted 12 November 2012 - 11:42 AM
local minFuelAmount = 200
while true do
if turtle.getFuelLevel() < minFuelAmount then
break
end
--do stuff when fuel is not below 200
end
--do stuff when fuel is below 200
1688 posts
Location
'MURICA
Posted 12 November 2012 - 12:25 PM
local minFuelAmount = 200
while true do
if turtle.getFuelLevel() < minFuelAmount then
break
end
--do stuff when fuel is not below 200
end
--do stuff when fuel is below 200
Problem with this is that there's no good way to get back into the loop once you've exited it because there's no fuel. Fuel checking should be done within the loop, and shouldn't break it, but halt it.
local minimumFuel = 200
while true do
while turtle.getFuelLevel() < minimumFuel do
turtle.refuel()
end
-- your digging code
end
25 posts
Posted 29 March 2013 - 08:34 PM
In theory, would this work?
local mf=5
for i = 1, 800 do
turtle.forward()
turtle.turnRight()
if turtle.getFuelLevel() < mf then
turtle.refuel(1)
end
end
The goal is to get it to go around in a square, refuelling when it needs it.
15 posts
Posted 09 April 2013 - 03:04 AM
In theory, would this work?
local mf=5
for i = 1, 800 do
turtle.forward()
turtle.turnRight()
if turtle.getFuelLevel() < mf then
turtle.refuel(1)
end
end
The goal is to get it to go around in a square, refuelling when it needs it.
Funny program - but should work B)/> why just refuel(1)?
169 posts
Posted 09 April 2013 - 03:12 AM
In theory, would this work?
local mf=5
for i = 1, 800 do
turtle.forward()
turtle.turnRight()
if turtle.getFuelLevel() < mf then
turtle.refuel(1)
end
end
The goal is to get it to go around in a square, refuelling when it needs it.
Funny program - but should work B)/> why just refuel(1)?
Presumably so that the turtle doesn't use more fuel than it needs. Sure, you could feed a turtle 16 stacks of coal. But it might never use them, and you will have wasted 16 stacks of coal.
13 posts
Posted 09 April 2013 - 05:04 AM
Whilst mining, a turtle will no doubt encounter coal.
What I usually do is put coal into a specific slot of the turtle, and then when the fuel gets below a threshold "Min Fuel Reserve Level", it scans the turtle's inventory for coal and refuels (1 unit at a time) until we hit a "Full Tank Level".
If it finds no fuel in the inventory, it'll go home.