6 posts
Location
In my Turtle : Home Edition.
Posted 21 November 2016 - 01:32 AM
Hey guys,
So… I have a turtle that will check through all slots and when it finds coal, it will run the turtle's refuel program. Now, I decided to do something, and that was to test planks, sticks, wooden tools, etc and they worked… This is not good for me as I would have to add lots and lots of "and"s in my if statement, or use a switch statement or something, but my question is… "Is there an easy way to check if the item in a selected slot is fuel?". Without listing every single item there is.
Here is my function at the moment (That only works with coal)
function refuel()
for i = 1, 16 do
turtle.select(i);
if turtle.getItemCount() > 0 then
if turtle.getItemDetail(i).name == "minecraft:coal" then
turtle.refuel();
print("Successfully added fuel!");
break;
end
elseif i == 16 then
print("No fuel found, please add fuel!");
break;
end
end
end
8543 posts
Posted 21 November 2016 - 01:45 AM
I believe in most recent versions turtle.refuel(0) will return true if the item could be consumed for fuel, but does not consume the item.
6 posts
Location
In my Turtle : Home Edition.
Posted 21 November 2016 - 01:51 AM
I figured out how to do it. Totally derped out here. Here is the new code. Thanks for your response though.
function refuel()
for i = 1, 16 do
turtle.select(i);
if turtle.getItemCount() > 0 then
if turtle.refuel() then
print("Successfully added fuel!");
break;
end
elseif i == 16 then
print("No fuel found, please add fuel!");
break;
end
end
end
6 posts
Location
In my Turtle : Home Edition.
Posted 21 November 2016 - 04:18 AM
Hey guys,
So I am having a problem with my turtle refueling everything that's NOT a sapling. If you look at the code below, ot should do just that, but instead, it just executes the elseif statement. If I take away the NOT infront of getItemDetail() it will only use the sapling as fuel, which WORKS… I have no idea why. Please… help…
Edited on 21 November 2016 - 03:23 AM
1220 posts
Location
Earth orbit
Posted 21 November 2016 - 04:29 AM
Instead of "if not" substitute ~= for == and see if that works.
if turtle.getItemDetail().name ~= "minecraft:sapling" and turtle.refuel() then
Edited on 21 November 2016 - 03:30 AM
6 posts
Location
In my Turtle : Home Edition.
Posted 21 November 2016 - 04:41 AM
Ah, of course. That worked like a charm! Thank you =)
7083 posts
Location
Tasmania (AU)
Posted 21 November 2016 - 05:01 AM
Threads merged; please stick to the one for the one project.
6 posts
Location
In my Turtle : Home Edition.
Posted 21 November 2016 - 05:15 AM
Threads merged; please stick to the one for the one project.
Ah, alright. Will do in future =)