Page 1 of 1

Basic lua question

Posted: Sat Feb 23, 2013 6:44 pm
by noatom
If I have this:

Code: Select all

t[2] = { "apple", "pear", "banana" }
how should I acces pear? t[2][2] or t[2].pear? Could I do this: t[2][2] = { "inception" } ?

And most importantly,what would happen if i'd run a loop to go through t? what would it output when it got to t[2]? cause t[2] has 3 elements!

Re: Basic lua question

Posted: Sat Feb 23, 2013 6:50 pm
by spectralcanine
Why not try it out?

print(t[2][2]) -- hint: it will print "pear"

Why does it matter in a loop that one of the elements is another table? you can use tables anywhere you want.

Re: Basic lua question

Posted: Sat Feb 23, 2013 7:25 pm
by Qcode
If you wanted it to print t[2].pear then you would have to do

Code: Select all

t[2] = {apple = "apple", pear = "pear", banana = "banana"}