Controlling multiple copies of an object?

I am trying to create a particle system and have the following code to add 100 copies of an object…

from bge import logic
import math
import random
particle_list = []
def spawner():
    scene = logic.getCurrentScene()
    cont = logic.getCurrentController()
    object = cont.owner
    global particle_list
    
    for n in range(0,100,1):
        x = random.uniform(-20,20)
        y = random.uniform(-20,20)
        z = random.uniform(0,20)
        object.worldPosition = [x,y,z]
        particle_list.append(scene.addObject("Icosphere",object,0))

It works correctly but I now have a list with 100 identical names! From reading the forums I know that an object name is read only so what work arounds are there to be able to control the individual particles?

Thank you,
Andrew

While the names are identical, the objects they represent are not. Simply iterate over your list and manipulate each particle, it should work fine:

for particle in particle_list:
    particle.worldPosition.x += random.random()

Also, you can replace range(0, 100, 1) with range(100) as they have the same behavior. You may also exclude the last parameter 0 from addObject, as it defaults to 0 anyway.

Brilliant, thank you.

Andrew