문제

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!

도움이 되었습니까?

해결책

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.

다른 팁

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])

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top