Question

This is an example of my code

inv = peripheral.wrap("right")
var1 = inv.getAllStacks()
var2 = var1[1] --This should set var2 to another table
print(var2[1])

When I execute this program on an advanced computer with a diamond chest next to it, with things inside, it prints nothing at all. please help me out with this!

Was it helpful?

Solution

Solved: What the getAllStacks() method does is returns a table full of dictionaries. So, to get the name of the item in stack one, you would do this:

chest = peripheral.wrap("right")
chestInv = chest.getAllStacks()
item1 = chestInv[1]
print(item1["name"]) --Because name is the term and the value is the name of the item.

this above code will print the name of the item in the first slot of chest.

OTHER TIPS

Use an addon (AddonCCPeripherals) and connect your chest with the Computer (with the proxy)! now you have to code:

chest = peripheral.wrap("diamond_0")
Diamond chest: "diamond_0"
Iron chest: "iron_0"

(sorry if there some Errors in my text, im from Germany [but the code is right])

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top