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

[Programming] How do I check to see what items are in a chest?

Started by EmTeaKay, 11 April 2012 - 11:54 PM
EmTeaKay #1
Posted 12 April 2012 - 01:54 AM
What code do I use to see what items are in a chest? So something like there is 40 redstone in a chest, but I want the computer to tell me how many are in the chest? Thanks in advance!
Luanub #2
Posted 12 April 2012 - 01:58 AM
I don't think that is possible. You would probably have to use RP or BC and load the items into a turtle and count its inventory. But even then its not going to tell you what it is that it is counting.
EmTeaKay #3
Posted 12 April 2012 - 02:10 AM
Sure? I just now saw this. http://pastebin.com/vTVR0Tjt I did NOT make this.
Luanub #4
Posted 12 April 2012 - 02:20 AM
yes


Manual Entry for the quantities
[list=1]
[*]	
print("Please enter the ammount of Copper Ingots.")
[*]	
        copper = io.read()
[/list]

Nothing in the code counts anything. He's using some other method to keep track.
MysticT #5
Posted 12 April 2012 - 02:26 AM
There's no way to do this with the basic CC functions, but you could use a peripheral. This one let's you do what you want: Advanced Resource Processing, it only works in ssp, so you can't use it on a server.
Znoorz #6
Posted 14 April 2012 - 11:13 PM
Well you kinda can, if you have only 1 item in the chest lets say only 23 redstone then you can pull out with a filter and let it go thru a item detector that will pulse on each item, which have an assaigned colour which the computer will recive and then keep the count, only works if there is only the same item in the chest.
con2000 #7
Posted 16 April 2012 - 12:01 AM
If You Use BuildCraft you can use (Gates) to show a specific item.
yoskaz01 #8
Posted 16 April 2012 - 02:31 AM
you can use ccSensors ( check peripherals forum)

it has an inventory sensor

u can use in lua to get # of items
mellotanica #9
Posted 05 December 2012 - 07:19 AM
i was searching for some api/code to check within a terminal if a chest was full and stepped onto this topic. it's not exactly the same objective, but i made up a system (with a little of buildcraft) that uses 2 chests and checks if one is full, in that case it begins to fill the second chest. if someone needs a thing like this i used this setup:


with this code running on left turtle:


try = turtle.suck()
while try == false do
os.sleep(1)
try = turtle.suck()
end
turtle.drop()
redstone.setOutput("right", true)
stop = false
c = 0
while stop == false do
os.sleep(1)
stop = redstone.getInput("back")
c = c + 1
if redstone.getOutput("right") == true then
  if c > 1500 then
   redstone.setOutput("right", false)
   c = 0
  end
else
  if c > 20 then
   redstone.setOutput("right", true)
   c = 0
  end
end
end
redstone.setOutput("right", false)

and this on the right one:

**Edit the right turtle code was buggy, this is a working version


try = true

while try == true do
  suck = turtle.suck()
  if suck == true then
    os.sleep(1)
    try = turtle.drop()
  end
  if turtle.compareTo(2) == false then
    try = false
  end
end

redstone.setOutput("back", true)

c = 3

while c < 17 do
 turtle.select(c)
 turtle.suck()
 c = c + 1
end

(one could use a terminal on the left side if he doesn't mind powering up the redstone engine for no task when the input box is unused)

the components are namely (from bottom left going clockwise):
- a chest (any type, silver chest in my case)
- wooden pipe
- redstone engine
- stone transport pipe
- another chest
- right turtle
- redstone dust
- left turtle

(it could also be compressed and built using one turtle and no redstone message by turning the turtle to make both checks and power on and power off, i made it this way because the turtle api specs are not clear about the side to witch turtle.drop function drops the item, but it actually drops only in front of the turtle so it is not a problem to have one turtle between two chests)