More lua help

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
User avatar
Fourex
Citizen
Posts: 53
Joined: Tue Nov 10, 2009 2:33 am
Location: Earth

More lua help

Post 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!
User avatar
bmelts
Party member
Posts: 380
Joined: Fri Jan 30, 2009 3:16 am
Location: Wiscönsin
Contact:

Re: More lua help

Post 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.
User avatar
Fourex
Citizen
Posts: 53
Joined: Tue Nov 10, 2009 2:33 am
Location: Earth

Re: More lua help

Post by Fourex »

Thanks!
Post Reply

Who is online

Users browsing this forum: No registered users and 22 guests