1

made in portuguese sorry

ok so basically i have this function:

function perfil(monstro)
 print(monstros.monstro.nomeM)
 print(monstros.monstro.racaM)
 print(monstros.monstro.generoM)
 print(monstros.monstro.idadeM)
 print(monstros.monstro.descM)
end

and this table:

monstros = {
  Esqueleto = {nomeM = "Skeletran", racaM = "Esqueleto", generoM = "F", idadeM = "455", descM = "'Estou morta mas não o suficiente!'"},
  Zumbi = {nomeM = "Bruce Santos", racaM = "Zumbi", generoM = "M", idadeM = "19", descM = "'Prociza ter umh celbro de 17 centismotros       .'"},
  Sirena = {nomeM = "Alamellia", racaM = "Sirena", generoM = "F", idadeM = "18", descM = "'Minhas canções são as melhores! Inspirante á Cantora :-D'"},
  Ogro = {nomeM = "Crak", racaM = "Ogro", generoM = "M", idadeM = "34", descM = "'hngbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbyæ'"},
  Dragoa = {nomeM = "SUZANA", racaM = "DRAGÂO", generoM = "F", idadeM = "1367", descM = "'GOOSTO DE FLORESS VERMELHHAS'"}
  }

and i want to make it so that io.read input changes the parameter monstro on the function perfil. sorry if the solution is something easy, i'm pretty new to programming and Lua. Also, if theres a error or bad thing in my code, tell me ! (i know i need to use this for accent marks)

1 Answer 1

0

Is this what you're looking for?

function perfil(monstro)
 monstro = monstros[monstro] --take the input and find the matching key in the table
 print(monstro.nomeM)        --print the corresponding 'nomeM' for that key
 print(monstro.racaM)
 --... and so on
end

perfil(io.read())   --call the function io.read() and take the input as parameter

I don't know what you actually intend to do with these keys but depending on what you need, you could iterate over them like this:

function perfil(monstro)
 print(monstro)
 for key, value in pairs(monstros[monstro]) do
  print("Key:", key, "Value:", value)
 end
end

perfil('Ogro')

Output:

Ogro
Key:    idadeM  Value:  34
Key:    generoM Value:  M
Key:    racaM   Value:  Ogro
Key:    descM   Value:  'hngbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbyæ'
Key:    nomeM   Value:  Crak
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.