Getting lights to render

I’m not worrying too hard about the last bit, what I’ve done is this:

Each time a bullet is created, a light source is also created and parented to the bullet. The bullet is then added to a list of bullets, the light source to a list of lights.

Upon creation, each bullet and life are set to expire after a given time (this is in the sample asteroid code for the bullets), and if they collide with something, this is set to zero, so that the bullet/light should expire next cycle.

What’s weird though, is that (I tried to say this before, but reading my post I don’t think I made it very clear) when if remove the bullet object, the light (which is parented to it) isn’t removed alongside it (ie. it remains in space, so that that section of the screen has a constant glow). This is why I then created the list of light objects: so that the lights could be individually removed.

So this approach seems to work: when a bullet collides and is destroyed, the light goes too. Which is why I think it’s a little weird that I can’t continue to produce light sources, since I remove them alongside the bullets; I could understand if there were a large number of lights on the screen at one time, but once I’ve lightsource.remove() 'd them, they shouldn’t continue to affect the scene? Or am I not doing something right?

The code I’m using to update the lights and bullets is:

    #update bullets
    newBulletArray = []
    newLightArray = []
    for obj in self.bullets:
      self.updatePos(obj, dt)         #Update the bullet
      #Bullets have an experation time (see definition of fire)
      #If a bullet has not expired, add it to the new bullet list so that it
      #will continue to exist
      if self.getExpires(obj) > task.time: 
          newBulletArray.append(obj)
      else: 
          obj.remove()              #Otherwise remove it from the scene
    
    for obj in self.Lights:
      if self.getExpires(obj) > task.time:
          newLightArray.append(obj)
      else:
          obj.remove()



    #Set the bullet array to be the newly updated array
    self.Lights = newLightArray
    self.bullets = newBulletArray 

(The bullet part was in the original sample). Every time bullet expiration is referenced throughout the rest of the code, light source expiration is inserted as well.

Oh, I have another query, but perhaps it’s not really relevant here… I’ll ask anyway: In normal python, we can remove objects (or variables or whatever) from memory by using

del object

or      del object.subobject

Why can’t we do that in panda - we have to use object.remove() instead?

EDIT::

Main problem solved - the issue lay in the fact that I didn’t realise that doing a lightsource.remove() didn’t also remove said light source from the lists of light sources affecting a given object (in this case the main render object). So the entire scene was continuing to be lit by lights which were no longer present, making it think I had way more lights than I did (and so it refused to deal with new ones properly). My new solution is a little nicer:

def removelight(self, light):
    if render.hasLight(light):
        render.clearLight(light)
    light.remove()