[Bf-committers] game engine: newNaming added objects?

Kester Maddock bf-committers@blender.org
Sat, 3 Jul 2004 13:32:17 +1200


Hi Toni,

On Friday 02 July 2004 23:02, Toni Alatalo wrote:
> I need to return an issue that was (last?) discussed here in September
> 2003, about referring to objects created with the addObject actuator in
> the game engine. The concluding message in the earlier thread is
> http://www.blender.org/pipermail/bf-committers/2003-September/004036.html
>
> The problem is that such added objects, as far as I know, all have the
> same name and can't hence be individually addressed by other actuators,
> e.g. targeted by using the camera actuator. A solution would be to apply
> the renaming that's used elsewhere in Blender too (the .001, .002 -thing),
> but as discussed in that previous thread, implementing it is not trivial:
> as the actuators are actually not run when they are called, they can't
> (straightforwardly) return resulting values, which in this case could be
> the name the newly added object got.
I think that will probably break some games.

I suggest either:
1.  provide obj.getName() & obj.setName() methods (or obj.name attribute) that 
you can use.  This means the game programmer is responsible for making the 
name unique, but is easy to implement so I'll probably do it anyway.
2.  Overload all the methods that take a game objects name.  They all just 
lookup the game object by name and store a pointer to the game object anyway. 
That means you would just:
newobj = act.getLastCreatedObject()
trackto.setObject(newobj)
3.  Add a setNewObjectName method to the add object actuator.  That way, when 
the add object actuator activates, it will rename the new object.
4.  Add a setUnique method to the add object actuator that generates a new 
name when adding the object.  This would tie in with #1 so that you can get 
the unique name getLastCreatedObject().

I think #2 is the most robust solution.  You can then point any actuators you 
want at an object with a script set up to run when the object is added.  Do 
you need a method like act.getObject() (which returns the target object's 
name) that returns a reference to the actual object?

Also, with the new scene python methods you can get a list of all the objects 
in the scene, which should make this sort of cross object scripting easier.

Kester