Page 1 of 1

Accesing tables within tables

Posted: Tue Feb 12, 2013 8:07 pm
by tolkien
One simple question:

Can I have a table
t1 = {boo = true, foo = false]

include that table within another table

t2 = {x=0, y=0, t1}

???

How do access to all members in t2?

Hope you understand.

Re: Accesing tables within tables

Posted: Thu Feb 14, 2013 11:50 am
by Bugala
Yes you can.

But if you wish to do it the way you arew doing in example, you need to do the second table in way of

t2 = {x=0, y=0, t1 = t1 }

Access to t1 would be:

t2.t1.boo
t2.t1.foo


you can have as many table dimensions as you like, and you can also assign them at once. say:

Code: Select all

table = {
     [t2] = {
             [t3] = {
                       [t4] = {   message="hello"   }
                    }
            }
      }


debugprint( table[t2][t3][t4].x  )

this should result in "Hello" being printed.

Re: Accesing tables within tables

Posted: Thu Feb 14, 2013 4:43 pm
by tolkien
Thanks Bugala. Clear enough! I dont know what happened to the rest of the thread but I understand clearly!