Page 1 of 1

More lua help

Posted: Sat Jan 09, 2010 1:41 am
by Fourex
So, I have a table,

Code: Select all

z = { {1, 2, 3, 4},
		{5, 6, 7, 8},
		{9, 10, 11, 12}
}
How do I call the different parts of the tables within "z"? For example, how get the third value in the second table (7) to use in a print function?
Many thanks!

Re: More lua help

Posted: Sat Jan 09, 2010 1:50 am
by bmelts
When you define a table like that, any entry without a specified key is given a numerical index, like an array. So, the first table there would be 1, the second table would be 2, etc. The same goes for the values within the tables.

So, the third value in the second table would be referred to by z[2][3]. z[2] points to the second table, and [3] points to the third value within that table.

Re: More lua help

Posted: Sat Jan 09, 2010 7:41 am
by Fourex
Thanks!