inventory management script help

Started by darklynightly, Sep 26, 2024, 06:56 AM

Previous topic - Next topic

darklynightly

Hi I am new to this mod, I was wondering how would I be able to get a computer to look into a chest and display how much space is left. Just lke the one shown in cc:tweaked main mod page

SquidDev

You can wrap inventories as a peripheral, and then use list() to list the contents of the inventory. For instance, if you just wanted to list the number of slots in use, you could do something like:

local inventory = peripheral.wrap("left") -- Get chest to the left

-- Get the size of the inventory
local total_slots = inventory.size()

-- Count the number of slots in use, and the total number of items
local used_slots, item_count = 0, 0
for slot, item in pairs(inventory.list()) do
  used_slots = used_slots + 1
  item_count = item.count
end

print("Slots: " used_slots .. " out of " .. total_slots)
print("Have " .. item_count .. " items")
GitHub | CC:Tweaked: A ComputerCraft fork | Plethora: A peripheral mod

darklynightly

#2
thank you so much, i now have an idea on where to start :)