Posted 23 March 2013 - 08:39 PM
I am starting on a new quarry program to improve my previous one that had some kinks. I first want to refine the dropoff function in which the turtle places down an enderchest, dumps it's contents into the chest(which goes to my sorting system), and if the turtle's inventory is empty it will continue with what it was doing, but if it is not(like if my sorting system is backed up or if too many turtles are dumping into it at the same time) then it will wait five seconds and then try again. Most of it works fine except for the part where it tries to figure out if it's inventory is empty. I have it printing out the total number of items in it's inventory, for debugging purposes, before dumping into a chest or deciding that it's inventory is empty. When it prints out how much it has, it doesn't update after dumping items into the chest. So basically, the outcome is it thinking that it still has items in its inventory even when it doesn't.
Code:
Also, there is some extra stuff besides the dropoff function for the quarry.
Help is appreciated!
Thanks! :D/>
P.S. Sorry, if this is hard to follow. I typed it at like 4 in the morning. :P/>
Code:
--Very repetitive way to find out if there are any items in the inventory
local inv = turtle.getItemCount(1)+turtle.getItemCount(2)+turtle.getItemCount(3)+turtle.getItemCount(4)+turtle.getItemCount(5)+turtle.getItemCount(6)+turtle.getItemCount(7)+turtle.getItemCount(8)+turtle.getItemCount(9)+turtle.getItemCount(10)+turtle.getItemCount(11)+turtle.getItemCount(12)+turtle.getItemCount(13)+turtle.getItemCount(14)+turtle.getItemCount(15)+turtle.getItemCount(16)
local function forward(forw)
curr = 0
for i = 1,forw do
while curr ~= forw do
if not turtle.forward() then
turtle.dig()
turtle.attack()
turtle.forward()
end
curr = curr+1
end
end
end
local function empty() --Dropoff starts here
turtle.select(16)
turtle.placeUp()
turtle.select(1)
select = 1
for i = 1,16 do
turtle.dropUp()
turtle.select(select)
select = select+1
end
sleep(5)
if inv == 0 then
print("Inventory is empty!")
print(inv)
turtle.select(1)
turtle.digUp()
turtle.transferTo(16)
else
print("Inventory didn't empty!")
print(inv)
sleep(5)
empty()
end
end --Ends here
print(inv)
empty()
By the way, if anyone knows a better way to find out how many items are in it's inventory please tell me! I am almost certain that their is a better way. Also, there is some extra stuff besides the dropoff function for the quarry.
Help is appreciated!
Thanks! :D/>
P.S. Sorry, if this is hard to follow. I typed it at like 4 in the morning. :P/>