Jump to content




Open Peripherals inventory.getAllStacks() issue

peripheral

3 replies to this topic

#1 Domi71097

  • New Members
  • 1 posts

Posted 16 May 2014 - 01:14 AM

I was having an issue with my code. I tried this several times and cannot find out what is wrong.
getAllStacks() should return a table with each and every item in a chest (after being wrapped) that contains several tables that all contain data.
so I tried this.
chest = peripheral.wrap("right")
var1 = chest.getAllStacks()
var2 = var1[1]
print(var2[1])

The above code prints nothing, yet I have the chest completely full. what could be the problem here and how can I fix it?

#2 joebodo

  • Members
  • 69 posts

Posted 16 May 2014 - 02:20 AM

chest = peripheral.wrap('right')
if not chest then
  error('no chest')
end
stacks = chest.getAllStacks()
if not stacks then
  error('all stacks returned nothing!')
end
stack = stacks[1]
if not stack then
  error('nothing in first slot')
end
for name,value in pairs(stack) do
  print(name .. ' = ' .. tostring(value))
end

Give the above a try. When I have trouble with some code, adding error checking and printouts often helps.

Edited by joebodo, 16 May 2014 - 02:20 AM.


#3 apemanzilla

  • Members
  • 1,421 posts

Posted 16 May 2014 - 03:45 PM

I believe the values in the stack tables (var2 in your code) are indexed by strings, not numbers. Try print(var2.name) or print(var2.Name)

Edited by apemanzilla, 16 May 2014 - 03:45 PM.


#4 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 17 May 2014 - 01:24 AM

apemanzilla is correct, we do not store information about the ideas under a numerical index. information about the itemstack is stored under the keys id, name, rawName, qty, dmg, maxDmg, maxSize where
id is the item id
name is (normally) the human readable name, such as "Cobblestone"
rawName is the java class name, such as net.minecraft.Block.BlockCobblestone (example, can't actually remember the class path and don't want to look it up)
qty is the amount of items in the stack
dmg is the metadata/damage value
maxDmg of course this is the max metadata/damage the item can have
maxSize the max amount of items that can be in the stack

Edited by theoriginalbit, 17 May 2014 - 01:25 AM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users