-1

I want to try and compare the two variables capacity and amount but I have no clue as to how to access the data. I will include screenshots from in-game. Here is the code:

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

The function returns the following.

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

EDIT: I got it. Its a table of tables. so to access it.

infoTable[1].capacity

and for the cotents table

infoTable[1].contents.amount

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

1 Answers1

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

Colonel Thirty Two
  • 23,953
  • 8
  • 45
  • 85