[Resolved] Creating multiple instances with "for" bucle

Hi all!
I was used to do games with flash, using AS2. Then I leaved it for a while, and now I have started doing games again, and I am trying Corona.

Programming with AS2 I was able to create multiple instances of an enemy doing something like this (I don’t remember of this is actually correct, but i hope you understand what I mean):

for (1=0, 1<10, i++)
{
_root[“enemy”+i] = newInstanceOf(enemy);
}

How should I handle to make the same with Corona?

I was checking the forums but I was not able to find any help.

I want to spawn 10 enemies in the stage, and then I will use another “for” to check and change their positions along the time.

Maybe there is another way to do this with Corona and what I am trying is just stupid. So, any hint from you will be welcome.

Thanks! [import]uid: 140715 topic_id: 27110 reply_id: 327110[/import]

Hey there,

If you have a function that returns the enemy you’d put that in place of my circle spawning, but hopefully this gives you an idea;

[lua]local enemy = {}

for i = 1, 10 do
–New enemy (a circle in this case), random x, random y, radius of 20
enemy[i] = display.newCircle(math.random(20,300), math.random(20,460), 20)
end[/lua]

Peach :slight_smile: [import]uid: 52491 topic_id: 27110 reply_id: 110094[/import]

I believe this guide will help you: http://blog.anscamobile.com/2011/09/how-to-spawn-objects-—-the-right-way/ [import]uid: 84637 topic_id: 27110 reply_id: 110121[/import]

Thanks for the answers!
I will start testing all that right now.
lua and Corona looks awesome, but seems to be a little more abstract than Flash/AS :S

Lets see what I get :slight_smile:

UPDATE: Just what i was looking for! Thanks. [import]uid: 140715 topic_id: 27110 reply_id: 110517[/import]