打开Peripherals getAllStacks()问题

时间:2014-05-16 00:55:03

标签: lua computercraft

这是我的代码

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

当我在高级计算机上执行此程序时,旁边有一个菱形胸部,里面有东西,它什么都没打印。请帮我解决这个问题!

2 个答案:

答案 0 :(得分:0)

解决: getAllStacks()方法的作用是返回一个完整的字典表。因此,要获得堆栈中项目的名称,您可以这样做:

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.

以上代码将在胸部的第一个插槽中打印该项目的名称。

答案 1 :(得分:0)

使用插件(AddonCCPeripherals)并将您的胸部连接到计算机(使用代理)!现在你必须编码:

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

(对不起,如果我的文字中有一些错误,我来自德国[但代码是对的])