Hi This is a very basic question, I was wondering how I could create a 2 dimensional table in lua, basically what I want to do is store to different lists of objects in one table, also how could I access those lists separately, thanks.
Basically, you can’t. Lua doesn’t even have one dimensional arrays, it has associative arrays (sometimes called hashes and maps) that pretend they are one dimensional arrays. So you have to build “arrays” of “arrays” a bit like you do in ‘C’.
e.g. this creates a 4 x 8 array that can be accessed via item[3][7] and so on.
item = {} for i = 1,4 do item = { 0,0,0,0,0,0,0,0 } end
Paul, shouldn’t that be:
item = {} for i = 1, 4 do item[i] = { 0,0,0,0,0,0,0,0 } end
???
… yes … too much beer
Basically, you can’t. Lua doesn’t even have one dimensional arrays, it has associative arrays (sometimes called hashes and maps) that pretend they are one dimensional arrays. So you have to build “arrays” of “arrays” a bit like you do in ‘C’.
e.g. this creates a 4 x 8 array that can be accessed via item[3][7] and so on.
item = {} for i = 1,4 do item = { 0,0,0,0,0,0,0,0 } end
Paul, shouldn’t that be:
item = {} for i = 1, 4 do item[i] = { 0,0,0,0,0,0,0,0 } end
???
… yes … too much beer