Jump to content




Using Tables?


2 replies to this topic

#1 makeme

  • Members
  • 60 posts

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?

#2 CometWolf

  • Members
  • 1,283 posts

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]

#3 lucySan

  • Banned
  • 4 posts
  • LocationPoland

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





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users