Addobject and endobject from same object

Hi there,
I have a question

Suppose I have 2 cubes, cubes A and B. Only A is visible because Cube B is on the 2nd scene. On object A I have a keyboard sensor and add object actuator which adds object B. And it works perfectly. The Second Cube will appear

The bad thing is I have to put another script/ sensor on object B itself to end it. Since the end object actuator doesnt allow you to select a object. It must be place on the object you are ending. Object B.

Is there a way maybe thru python I can end Object B from object A, where I have the addobject script to begin with?

MAny thanks in advance

Yep, it’s actually very easy. After spawning the object, you can get and end it with a pointer to the object:


from bge import logic

sce = logic.getCurrentScene()

cont = logic.getCurrentController()
obj = cont.owner

if not 'init' in obj:
     obj['init'] = 1
     obj['objectb'] = sce.addObject('ObjectB', obj)

# When you want to destroy object B

obj['objectb'].endObject()

Could you tell me what your were going to use this for or you want to
keep it a secret?My idea maybe similar or maybe not.

This script doesnt have the problem of the add object actuator when it adds a cube with a empty parented to it.And the empty parented to the cube has a add object actuator on it that adds a cube the cube gets bigger.If it does do this without error could i have the script please solarlune?

I’m not sure of your question, but if you’re talking about the script above, feel free to take it and use it for what you want.

A Killer Object?

It can become handy if an object that added another ends it when trying to add a new one.

For this reason I let Prof. Monster develop a new module for you. Here is the brand-new lastAddedmodule incl. a demo.

:wink:
Monster

Oh this was solved, btw this worked for me I was just unable to use it because I had to specify the object in the script. But it taught me how to use it.