Posted 30 January 2014 - 04:49 PM
Here is my code:
The problem I am having is that sellItems.Size becomes the same size as items[j].Size if the stack size is the same as one that went through previously. so if I have 4 stacks of 64 it goes 64+64 = 128 like it should, but the next time it is 128+128 which is obviously wrong.
os.loadAPI("ocs/apis/sensor")
os.loadAPI("ocFunc")
monitor = peripheral.wrap("right")
--*********Variables**********
sensorSide = ocFunc.sensorSide()
curPlayer = ocFunc.playerName(sensorSide)
--**********Helper Functions**********
function newLine(monitor)
local _,cY = monitor.getCursorPos()
local _,mY = monitor.getSize()
if cY==mY then
monitor.clear()
monitor.setCursorPos(1,1)
else
monitor.setCursorPos(1,cY+1)
end
end
function table_count(tt, item)
local count
count = 0
for i=1,#tt do
if item == tt[i].RawName then
count = count + 1
end
end
return count
end
items = {}
invPlayer = false
sellItems = ocFunc.playerInventory(sensorSide, curPlayer)
if sellItems[1] then
invPlayer = true
end
if invPlayer then
for i=1,#sellItems do
count = table_count(items, sellItems[i].RawName)
if count == 1 then
inv = sellItems[i].RawName
for j=1,#items do
item = items[j].RawName
if item==inv then
local itemSize = tonumber(items[j].Size)
local sellSize = tonumber(sellItems[i].Size)
monitor.write("Items: "..itemSize.." + SellItems: "..sellSize.." ")
items[j].Size = tonumber(itemSize + sellSize)
monitor.write("Items: "..items[j].Size)
newLine(monitor)
end
end
else
table.insert(items, sellItems[i])
end
end
end
The problem I am having is that sellItems.Size becomes the same size as items[j].Size if the stack size is the same as one that went through previously. so if I have 4 stacks of 64 it goes 64+64 = 128 like it should, but the next time it is 128+128 which is obviously wrong.