ComputerCraft Forums

ComputerCraft => Ask a Pro => Topic started by: darklynightly on Sep 26, 2024, 06:56 AM

Title: inventory management script help
Post by: darklynightly on Sep 26, 2024, 06:56 AM
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
Title: inventory management script help
Post by: SquidDev on Sep 26, 2024, 03:40 PM
You can wrap inventories as a peripheral, and then use list() to list the contents of the inventory (https://tweaked.cc/generic_peripheral/inventory.html). 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")
Title: inventory management script help
Post by: darklynightly on Sep 27, 2024, 04:29 PM
thank you so much, i now have an idea on where to start :)