This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
macss_'s profile picture

Count itens in a chest

Started by macss_, 20 May 2014 - 02:26 AM
macss_ #1
Posted 20 May 2014 - 04:26 AM
Is there a way that I can make my turtle count how much itens are in a chest?
CometWolf #2
Posted 20 May 2014 - 08:53 AM
Unless you have openP installed, no.
MKlegoman357 #3
Posted 20 May 2014 - 09:27 AM
Actually, you can, but it would take a little time to count it.

What I would do is suck all items from the chest, while counting how many I sucked, and put them into another chest. Then put them back from one chest to another if necessary.
theoriginalbit #4
Posted 20 May 2014 - 09:34 AM
definitely possible using the technique MKlegoman357 suggested. assuming you have something like an iron chests mod installed you could easily have the Turtle count the items in any chest in a few lines of code. If you want to use his method you'll need to take a look into the Turtle API.
macss_ #5
Posted 20 May 2014 - 04:29 PM
How can I do using openP cuz I have it!
theoriginalbit #6
Posted 21 May 2014 - 02:11 AM
you need to wrap the chest as a peripheral. And make use of the getAllStacks method; this will give you a table of tables representing all the items in the chest, you then loop through the, and get the quantity of from each table, the quantity is stored under the qty key. All in all, its about 5 lines of code.