chest.condense() --Organize the Chest
local slotnum = chest.getSizeInventory() --Use the Max Invantory Size to calculate the Slot number and Loop amount
while true do
sleep(5)
--push completed items out of the mace and efurn--
mace.push("north", 1, 64)
efurn.push("up", 1, 64)
--start looking for ore--
for i=1,slotnum do -- LOOP!
local tableInfo = chest.getStackInSlot(i)
if tableInfo ~= nil then
for key, value in pairs(tableInfo) do
if string.find(value, "Ore") then -- Find Ore
print("Ore Found! Moving to Macerator!")
chest.push("north", i, 64)
end
end
end
end
end
Also, is it just me, or does OP not understand what a double chest is? I'm pretty sure when you connect it with a ProxyBlock it thinks its a single chest and not a double.
edit:
Ok so I figured out what the issue was and here is how I fixed it.
chest.condense() --Organize the Chest
local slotnum = chest.getSizeInventory() --Use the Max Invantory Size to calculate the Slot number and Loop amount
local i = 0
while true do
sleep(.5)
i = i+1
--push completed items out of the mace and efurn--
mace.push("north", 1, 64)
efurn.push("up", 1, 64)
--start looking for ore--
local tableInfo = chest.getStackInSlot(i)
if tableInfo ~= nil then
if string.find(tableInfo.name, "Ore") then -- Find Ore
print("Ore Found in slot "..i..". Moving to Macerator!")
chest.push("north", i, 64)
else
shell.run("clear")
print("Chest contains "..tostring(slotnum).." slots")
print("Slot "..i.." contains no Ore")
end
else
i = 0
end
if i == 27 then
i = 1
end
end
When the code that finds the ore finds nothing, it starts spits out a nill. My code said "if tableinfo ~=nil then do stuff" so it would work for a while and then die out. I figured out that it was failing right after it hit slots with NO items in it. This would cause a Nil and the code would do the else command. If the code spit out nil to many times the while true do loop would kill itself which is likely a failsafe in Computercraft. The reason I never got an error is that when the code did present me a nil I told it to do something. So it did what I asked and never showed me the nil error.
To fix this i changed what happened in the Else portion of the "if tableinfo ~= nil then". Instead of posting a message, I told it to reset the i variable to 0. This stops it from getting to many nil errors and starts from the beginning again. As long as there is one item in the chest that can't be moved then it will loop forever.
I've cleaned this up a lot, made it only look for the key value of Name in the tableinfo table. This allowed me to get rid of the "for i=1,slotnum do" and the for key, value in pairs(tableInfo) do portion of the code because it was redundant. Now the code works exactly like I need it to. It finds anything that has Ore in its name and moves it to the Macerator and gets the smelting process going. The only downside i've found so far is that it finds items like Cinnabar Ore, which can't be used in a macerator. I'm sure I can figure out a way to add items to a filter or something later.


This topic is locked










