1 posts
Posted 16 May 2014 - 02: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?
69 posts
Posted 16 May 2014 - 03: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 on 16 May 2014 - 01:20 AM
1610 posts
Posted 16 May 2014 - 04: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 on 16 May 2014 - 02:45 PM
7508 posts
Location
Australia
Posted 17 May 2014 - 02: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 on 17 May 2014 - 12:25 AM