This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
makeme's profile picture

Using Tables?

Started by makeme, 26 February 2014 - 08:31 PM
makeme #1
Posted 26 February 2014 - 09:31 PM
I'm trying to wrap my head around openPeripherals but I'm having issues working out how to access the info shown in the table created when using "getTankInfo()" How can I see it?
CometWolf #2
Posted 26 February 2014 - 10:17 PM
Just use a for loop to get all the elements in a table

for k,v in pairs(table) do
  print("["..k.."] = "..v)
end
To acess the fields, just use table.key
if the field is a number, use table[key]
lucySan #3
Posted 27 February 2014 - 11:20 AM
Also, you can use variable as table key, for example:
local key = "black"
term.setBackgroundColor(colors[key])

You can think about square brackets in tables as "get value from stuff inside and use it as table key".