The program looks like it should work on all accounts

Started by IRONDOGKILLER, Jan 22, 2023, 06:28 AM

Previous topic - Next topic
Hello just wondering if I have done something wrong, as this program doesn't work as intended.

It works with a full inventory but if some of the slots are empty it doesn't work. It also provides bad information. The code looks right to me but it just won't work.



local manager = peripheral.find("inventoryManager")
local box = peripheral.find("chatBox")

if manager == nil then error("Inventory Manager not found") end
if box == nill then error("chatBox not found") end

print("Emptying...")

while true do
    event, username, message = os.pullEvent("chat")

    if username == manager.getOwner() and message == "dump" then
        print("Dumping slot 9 to 17")
        myInventory = manager.getItems()
        local itemTable = {}
        for keys, vector in pairs(myInventory) do
            table.insert(itemTable, keys, vector)
        end
        for keys, vector in pairs(itemTable) do
            if keys >= 9 and keys <=17 then
                print(("Slot:%d Item:%s Count:%d"):format(keys, vector.name, vector.count))
                manager.removeItemFromPlayer("LEFT", vector.count, keys)
            end
        end
    end
end

It was just advanced peripherals making an undocumented change to items tables.