Deleting objects made with Add object using python in 2.49b

Hi there
I’m adding loads of objects to a scene using the ADD OBJECT actuator but I don’t want each of these to sense a collision ( basically a big bulldozer is going to them) and then delete themselves as that slows things down too much.

So I am trying to write a script attached to the Bulldozer (my python is crap) to delete the objects when it touches them.

I’ve got the unique id() thing… which is great but I don’t seem to be able to do anything with it. even if I just try and convert it back to the object name and print it immediately afterwards I get IndexError: from_id(#):id not found in CValueList

So question is:
How do I delete an object from a scene by its id (or is there an easier way)

scene = GameLogic.getCurrentScene()
cont = G.getCurrentController()

S = cont.getSensor(‘sense’)

H = S.hitObjectList

for name in H:
OBID = id(H)
print OBID
ob= scene.objects.from_id(OBID)
print “new name is”, ob

Maybe mypost wasn’t very clear. Instead of all the ADD Objects having their own logic bricks sensng a collision and thus ending the object. I would like a script to run from the Bulldozer, which detects the collision, sees which other object it has bumped into, and ends that other object.

I want to do this because I am creating a lot of objects and having each detect their own collisions with the Bulldozer is slowing things down too much.

I’ve read the API stuff but I really don’t understand all this stuff about KX Gameobjects etc.
I have got as far as managing to get a unique ID from the ADD OBJECTS… but I dont know how to delete them from this information.

ANy vaguely useful response gratefully received.

I hate python. Eveytime I learn some, the next version of blender comes along and what I’ve learned has become ‘depreciated’, and soon, with python version 3, I’ll have to learn it all over again :frowning:

All you need to do is to write :
for name in H:

Please note that this iterates the objects not names, so you should rename ‘name’ to smth like ‘obj’

import GameLogic as GL
Cont = GL.getCurrentController()

Sensor = Cont.sensors["sense"]

HitObjects = Sensor.hitObjectList

for Object in HitObjects:
    if Object.has_key("Rock") == True:
        print "Rock Destroyed"

This code will just remove any object that touches the bulldozer. The object that it touches must have the property “Rock”.

You might not be able to straight copy past the code because of the white spaces.

Thanks to both of you.

Bull-frog, your script works like a dream. Thanks again