adding objects

Hey all,

I’ve just arrived on this great forum. nice to see you all :slight_smile:

Obviously I’ve arrived here in search for an answer.

The question goes:
when using the edit object actuator to add an object in game, every object that gets added this way has the same name. How do I go about addressing just one particular object of those I have added in this way in python to for example change its position?
Can you just rename them, and keep them apart in this way?

sincerely,

Once you add a object you have to make reference to it, in order to save it:

cont = GameLogic.getCurrentController()

addObject = cont.actuators['add']
addObject.instantAddObject() # Use this method when adding objects in python
new_object = addObject.objectLastCreated

Then you just have to save it some place safe, like the globalDict:

GameLogic.globalDict['added object'] = new_object

Recalling it is now easy:

object = GameLogic.globalDict['added object']
object.position = [0,5,0]

You don’t need to rename them. You can address them in two ways. Either get a pointer directly to that object, or get it’s python id and address it by that.

Using the add object actuator you can get the object by using:
object = actuator.objectLastCreated
object[“some_property”] = “some value”

http://www.blender.org/documentation/249PythonDoc/GE/GameTypes.KX_SCA_AddObjectActuator-class.html

If you’re using the scene.addObject() you just use:
object = scene.addObject(“obname”, “otherobject”)
object.worldPosition = some_value

http://www.blender.org/documentation/249PythonDoc/GE/GameTypes.KX_Scene-class.html

Or you could get the python id using:
object_id = id(object)

then you search for that object using, for example:
object = scene.objects.from_id(object_id)

seems easy enough, thx
i’ll give it a try