Having a problem with a farming turtle script. It's supposed to go through and get a row of wheat and melons in a zig-zag fashion, then dig up a row of melons at the end of the field.
That part works perfectly. However, near the end, I wanted to automatically craft bread and throw it in the chest before it, but it's not really working out very nicely.
Here's the part of the script that controls bread crafting:
local total = 0
for i=1, 16 do
total = total + turtle.getItemCount(i)
end
for i=1, 16 do
if turtle.getItemCount(i) > 0 then
turtle.select(i)
repeat until not turtle.dropDown(1)
end
end
for slot=1, 3 do
turtle.select(slot)
for w=1, math.ceil(total/3) do
if not turtle.suckDown() then
break
end
end
end
turtle.craft(turtle.getItemCount(1))
My logic with this was to throw out anything that isn't wheat (in slot 1) in the chest in front, then count all of the remaining items, which all should be wheat. Then it drops all of the items down, 1 by 1. After that, it sucks up a third of the dropped items into slots 1, 2, and 3, then crafts it at the end.
The full code:
Spoiler
local function wheat()
turtle.select(1)
turtle.digDown()
turtle.select(2)
turtle.placeDown()
turtle.forward()
end
for x=1, 9 do
for y=1, 6 do
wheat()
end
if x ~= 9 then
if x%2 == 1 then
turtle.turnRight()
wheat()
turtle.turnRight()
else
turtle.turnLeft()
wheat()
turtle.turnLeft()
end
end
end
local function melon()
turtle.select(5)
turtle.digDown()
turtle.forward()
end
turtle.forward()
turtle.turnLeft()
for i=1, 8 do
melon()
end
turtle.turnLeft()
melon()
for i=1, 6 do
turtle.forward()
end
turtle.select(1)
for i=2, 16 do
if not turtle.compareTo(i) then
turtle.select(i)
turtle.drop()
turtle.select(1)
end
end
local total = 0
for i=1, 16 do
total = total + turtle.getItemCount(i)
end
for i=1, 16 do
if turtle.getItemCount(i) > 0 then
turtle.select(i)
turtle.dropDown(1)
end
end
for slot=1, 3 do
turtle.select(slot)
for w=1, math.ceil(total/3) do
if not turtle.suckDown() then
break
end
end
end
turtle.craft(turtle.getItemCount(1))
for i=1, 16 do
turtle.select(i)
turtle.drop()
end
turtle.turnLeft()
turtle.turnLeft()
At the end, it only drops everything on the ground. That or just throws all the wheat in the chest, uncrafted. What am I doing wrong here?
for i=1, 16 do
if turtle.getItemCount(i) > 0 then
turtle.select(i)
repeat until not turtle.dropDown(1)
end
end
right there you are telling it to go through all 16 slots, if they have items toss them out, you do not check if it is wheat first, you should have wheat in the first slot always and then use the code
turtle.select(1)
for i=2,16 do
if turtle.getItemCount(i)>0 and not turtle.compareTo(i) then
turtle.select(i)
turtle.dropDown(turtle.getItemCount(i))
turtle.select(1)
end
end
Use turtle.transferTo as well, it'll make this sort of thing far simpler.
Probably should've mentioned that I'm in FTB.
KaoS, on 17 December 2012 - 04:26 PM, said:
for i=1, 16 do
if turtle.getItemCount(i) > 0 then
turtle.select(i)
repeat until not turtle.dropDown(1)
end
end
right there you are telling it to go through all 16 slots, if they have items toss them out, you do not check if it is wheat first, you should have wheat in the first slot always and then use the code
turtle.select(1)
for i=2,16 do
if turtle.getItemCount(i)>0 and not turtle.compareTo(i) then
turtle.select(i)
turtle.dropDown(turtle.getItemCount(i))
turtle.select(1)
end
end