I have been using Corona / LUA for 6-8 weeks and have a nice game in development. However I’m stuck on the best way to create lists of game / display objects…
I have a function that creates a new enemy using sprite.newSprite( spriteSet1 ) and then adds extra records like type, directions, behaviours etc.
enemy = spawnNewEnemy (type, xpos etc…)
this works, but what if I have 5 enemies and I want to access the 3rd enemy, I have tried the code below but it doesn’t work
enemyList = {}
for i = 1,5 do
enemy = spawnNewEnemy( data in here…)
enemList[i] = enemy – using enemyList{} to store each enemy —
end
when I try to access the 3rd enemy e.g. enemy = enemyList[3] it returns nil…
is this because I’m trying to make a table of a table?
Thanks for help, the LUA manual doesn’t seem to shed much light on this.
PS The only work around I can see is to create a record that contains a unique identifer and then cycle through all the objects looking for that…
[import]uid: 3093 topic_id: 10776 reply_id: 310776[/import]