tuxico
Member
- Joined
- Aug 2, 2010
- Messages
- 52
- Solutions
- 1
- Reaction score
- 7
I'm trying all day to learn about "Tables" in LUA, but it seems complicated or does not have enough content on nested tables ... come on
I've created a table that does not only contain a Key and Value, it has several variables as well, as is common in any pokemon server or whatever ...
The Table
I want to access the variables within the table, by name in [], which as far as I know, are Keys; Ie I want to get the values of a line, having only the ID, which in the monster would be 1515 ... already tried various forms and nothing, console ever return "Nil Value".
CODE EXAMPLE
I've created a table that does not only contain a Key and Value, it has several variables as well, as is common in any pokemon server or whatever ...
The Table
Lua:
Table = {
["demon"] = 1515, Vida = 5000, Level = 80, and other variables...
["orc"] = 1516, Vida = 3000, Level = 40, and other variables...
["rat"] = 1517, Vida = 1000, Level = 20, and other variables...
}
CODE EXAMPLE
Lua:
NovaPB:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, "It a Contain a " .. PokeLife .. ".")
local vida = getLifeForPoke(Table, demon)
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Pokemon Life: " .. vida)
function getLifeForPoke(t, nomepokemon)
for k,v in pairs(t) do
if k == nomepokemon then
return k.Vida
end
end
end