-1

我想尝试比较两个变量容量和数量,但我不知道如何访问数据。我将包括游戏中的屏幕截图。这是代码:

t=peripheral.wrap("left")
local infoTable = t.getTankInfo("west")
print(infoTable.capacity)

该函数返回以下内容。

{
 {
  capacity = 16000,
  contents = {
    id = 0;
    amount = 0,
  },
 },
}

编辑:我明白了。它是一张桌子。所以要访问它。

infoTable[1].capacity

对于 cotents 表

infoTable[1].contents.amount

http://puu.sh/gtzX9/acc0839b11.jpg
http://puu.sh/gtzZW/6b2aa52f12.jpg

4

1 回答 1

1

foo[bar] takes whatever is in the variable bar and uses it to index foo. Since in your example, variable capacity doesn't exist, it's value is nil.

You want infoTable.capacity, which is the same as infoTable["capacity"]

于 2015-03-09T21:56:20.477 回答