I seem to be having a problem with multidimensional tables (arrays?) on Lua. I have one that looks something like this:
arr =
{
"stats" = {
"23" = {
"1" = {
"account_id" = "10",
"info" = {
"name" = "john"
}
}
}
}
}
and whenever I try to access some info using like:
local entry = "23"
print(arr['stats'][entry]['1'])
or
print(arr['stats'][entry]['1']['info']['name'])
I get nil values, is mixing strings with variables when calling tables even allowed? any idea what I'm doing wrong?
It seems that lua does not accepts things like
so, either you do
or you do
That way, your table must be rewritten as this, in order to run on lua 5.3 interpreter:
doing this, your line
runs fine.
Also, it is not good practice to use brackets when you can use a dot. It is not that your script will not run otherwise, but the code gets a lot more legible and easier to debug if you wirte that line like this:
Hope that helps...