r/ComputerCraft • u/ExplodingHacker • Oct 03 '24
Need help programming a system that finds all chests connected to a single computer and showing all items placed in that storage
I started learning programming in cc a few days ago, and now i wanted to make a storage program which shows me all items scattered across numerous chests, to which i can add more chests at any given time without the need of changing or adding more variables. i tried experimenting with the code but nothing seemed to work
- local chest = {peripheral.find("minecraft:chest")}
- for slot, item in pairs(chest[1].list()) do
- print(("%d x %s "):format(item.count, item.name))
- end
this is the code i came up with. it does manage to find the connected chests and tell me the content of one of them, but i couldn't get it to tell me the content of all of them at once. I tried to reference the variables of the table manually - line 3: (chest[1][2][3]). but it didnt work, and it said that variables [2], [3] are nill. I'm out of ideas. Can i get some help?
3
u/Playful_Bearr Oct 03 '24
You should iterate over the length of chests
If i'm not mistaken, you can run something like
for i = 1, #chests do <Your code here with chests[i]> end
1
u/Weak-Description-621 Oct 03 '24
why do you have curly brackets around peripheral.find? you are putting the returned table inside another table