Help with multi-dimensional tables

Hi people,

This must we very basic but I am stuck. I want to create a table:

 a b c d   
1  
2  
3  
4  

I want to be able to write

local t = {}  
  
t["a"][1] = "value 1"  
t["a"][2] = "value 2"  

and so on. But that way it doesn’t work obviously. Can you, please, help me out?

Thank you all in advance [import]uid: 40334 topic_id: 16063 reply_id: 316063[/import]

I am not an expert, but i think you should do this:

local t = {}
t[“a”] = {}
t[“a”][1] = “value 1”
t[“a”][2] = “value 2”
t[“b”] = {}
t[“b”][1] = “value 3”…

and so on…
[import]uid: 75034 topic_id: 16063 reply_id: 59711[/import]

Thnks guys! It works. [import]uid: 40334 topic_id: 16063 reply_id: 59715[/import]

i would handle like this:

good link to understanding lua tables

http://www.gammon.com.au/forum/?id=6036

[lua]t[“a”] = {“value 1”,
“value 2”,
“value 3”,
“value 4”,
“value 5”} [import]uid: 7177 topic_id: 16063 reply_id: 59712[/import]

@Darkmod yes thats the quick way to do it if you know all the values…

Good that worked for you eugen

Have a nice day [import]uid: 75034 topic_id: 16063 reply_id: 59720[/import]

There were two set of tutorials written about tables in Lua

Part #1 here
and Part #2 here

Cheers,

?:slight_smile: [import]uid: 3826 topic_id: 16063 reply_id: 59726[/import]