Function not working as expected

I have created a function to do the some code creating multiple enemies however it is only creating one. when i have this code outside of the function it creates multiple sprites, can anyone please help as I am unsure why this is happening and what I can do to change this interaction.



In the function the variable “enemy1” is being overwritten and when the code is in the onstart it is not.
Thanks in advance.
louis

What happens if, instead of passing in the sprite, you define the sprite within the loop of the function?

Would you mind posting the link to your code so we can play around?

Ok so I’ve figured out a way of doing it. A little messy but it works.
I pass a sprite into the function,
I also define/set a sprite in the function, then change the image of the function sprite to that of the one in the parameter.
And then destroy the parameter sprite.

I would actually like to pass in an animation to the function. Is that possible? I can add them all to an array and the iterate through it outside of the function but my idea was to have this function create multiple rows of different sprites.

Thanks for your help