http://www.learn-corona.com/2010/10/an- ... comment-12
I like very structured tables, it feels "natural" organizing in this way. Do someone use this deeper hierarchical tree data storage? It's efficient enough like he asks?
and also I'd love to know if as in the poster answer you usually use or think it's a good "shortcutting/indexing" method:Supposing you have to use a container for hosting in-play data, which may be accessed (with get/set functions) at every frame in a game, how would you construct a Lua table to do this efficiently?
Flat Solution:
data={
opponents=2
anger=5
bonuses=6
hits=0
lives=3
energy=10
…
}
Structured Solution:
data={
scene={
bonuses=6,
enemies={
opponents=2
anger=5
}
},
player={
hits=0
lives=3
energy=10
}
}
I find the second way more convenient, but, from your experience with Lua, is deep-level table indexing (x=data.scene.enemies.anger) efficient enough, performance wise, for use in Update() calls?
Thank you in advance for your thoughts!data = {2, 5, 6, 0, 3, 10}
-- assign the indices to variables (if possible, use local variables)
opponents = 1
anger = 2
bonuses = 3
hits = 4
lives = 5
energy = 6
-- examples:
myBonuses = data[bonuses]
myEnergy = data[energy]