So I started this project that will enable me to get a listing of the items that pass through my spawner adding it to a text file which can later be reviewed online (Apache virtual host pointing to the file) or using monitors in game. I wrote the code along with a friend of mine and we got it working on a 2 dimensional array. Everything seems to be working but the fact that every time it Adds an item to the array that is already there it adds a new line for it. We have looked through the code and cannot see a reason for this to be happening. So I have come to you :)/>
The items enter the chest on the right from the spawner. After the system resets the Itemducts are activated using a rednet cable (Brown) after pulling for 10 seconds the computer changes it's output to black then proceeds to index the items that are in the chest in front of it (Using open peripherals). After indexing it rights to the file then activates Orange allowing the items to flow into the enderchest then starts over again.
c = peripheral.wrap("container_chest_3")
file = items
redN = colors.brown -- Rednet On colour
redNO = colors.black -- Rednet Off colour
EnderC = colors.orange -- Colour left on Enderchest when counting
redNS = "right" -- Rednet cable side
redNE = colors.orange
itemFile = {}
itemFile[1] = {}
itemFile[1][1] = 0
itemFile[1][2] = 0
function getItems()
for i = 1,27 do
itemArray = {}
if c.getStackInSlot(i) then
print("See if anythings in there")
data = c.getStackInSlot(i)
amount = table.getn(itemFile)
for i = 1,amount do
if itemFile[i][1] == data.name then
print("Is in the array")
itemFile[i][2] = itemFile[i][2] + data.qty
else
print("Not in table D:")
print(data.name..data.qty)
table.insert(itemArray,data.name)
table.insert(itemArray,data.qty)
for key,value in ipairs(itemFile) do
print(key, value)
end
table.insert(itemFile,itemArray)
end
end
end
end
end
function writeFile(line)
local diskFile = fs.open("disk/items","w")
amount = table.getn(itemFile)
print(amount)
for i = 2,amount do
text = itemFile[i][2].." X " ..itemFile[i][1]
print(itemFile[i][1]," ",itemFile[i][2])
diskFile.writeLine(text)
end
diskFile:close()
end
while true do
print("Setting EnderChest")
redstone.setBundledOutput(redNS,redN)
print("Tranfering Items")
sleep(10)
redstone.setBundledOutput(redNS,redNO)
getItems()
writeFile()
print("Written to file")
redstone.setBundledOutput(redNS,redNE)
sleep(10)
redstone.setBundledOutput(redNS,redNO)
print("item's sent to the ME")
end
Any help is appricated,
Thanks a lot,
Vennom.