Multidimensional Array in Lua

Asked

Viewed 52 times

1

I’m trying to insert an array within a multidimensional... Example:

local info = {
  [1] = {name = Felipe, idade = 21, rua = Alvorada},
  [2] = {name = Carlos, idade = 23, rua = Lima},
  [3] = {name = Sabrina, idade = 19, rua = Principal}
}

local cidades = {
  ['Central'] = {info[1], info[2], info[3]}
}

I tried every way up to my knowledge, I used loops for and while, and I couldn’t find a solution, where I’m missing?


I did it this way and it worked!

cidades = {}
cidades['Central'] = {}
for i = 1, #info do
   cidades['Central'][i] = info[i]
end
  • What is your doubt then?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.