0

这是我的代码示例

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

当我在一台旁边有一个钻石箱的高级计算机上执行这个程序时,里面有东西,它什么也没打印。这个你能帮我吗!

4

2 回答 2

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.

上面的代码将在箱子的第一个插槽中打印项目的名称。

于 2014-05-21T20:08:52.590 回答
0

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

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

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

于 2017-01-19T19:25:23.500 回答