Accesing tables within tables

Find quick help here to get you started with Hollywood
Post Reply
tolkien
Posts: 195
Joined: Sun Oct 17, 2010 10:40 pm
Location: Spain

Accesing tables within tables

Post 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.
Bugala
Posts: 1399
Joined: Sun Feb 14, 2010 7:11 pm

Re: Accesing tables within tables

Post 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.
tolkien
Posts: 195
Joined: Sun Oct 17, 2010 10:40 pm
Location: Spain

Re: Accesing tables within tables

Post by tolkien »

Thanks Bugala. Clear enough! I dont know what happened to the rest of the thread but I understand clearly!
Post Reply