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

Toni Alatalo bf-committers@blender.org
Fri, 2 Jul 2004 14:02:06 +0300 (EEST)


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.

Some possible ways around this were mentioned (i'll paste them at the end
of this message) -- could someone implement some, or something else? I
don't personally need this, as am getting the references to the objects
themselves and using those (and don't use the actuators that would need
the names), but am asking on behalf of a friend whose game development is
currently stalled because of this. It's probably a problem for many others 
too. Of course I'm considering doing it myself, too, but don't currently 
have the time nor skills (have never worked with c++ really).

About the possible implementations, quoting Thomas Dyar:

"What if you could get the name when you call getLastCreatedObject() on
the actuator the next logic cycle? Is it too late then? This could be done
with a sequencer like you mentioned. I think the main method that needs to
be called is scene->m_mapStringToGameObjects.insert(mn,gameobj); The name
needs to be chosen first, and this could be done by trying names based on
the original object until one was found that wasn't being used yet. This
would be bad when many objects were added, but you could make it more
sophisticated later."

I believe this would be feasible, i.e. that getting the name in the next
cycle would not be too late. Also that limitation for not supporting
several additions / cycle might be acceptable to start with, but is it
actually there, as Thomas noted in the same message (but in another
context) also the following: "Seems like you could have several actuators
called each logic cycle, since each keeps its own "lastcreatedobject"
reference."

Other than that:

"There was also the suggestion that a "sub-cycle" of the game engine be
run to handle ONLY newly added objects. Could be run without rendering, so
new objects could be initialized. Then the name given the object (by the
game engine or by a newName function) could be placed in the trackto
actuator on the next full cycle."

Does this mean that the initialization would be immediate so that the call
could return the new name? (which would of course be nice for the
programmer, not having to do the trickery to get the name in the next
cycle).

Looking forward to any insights,
(but being mostly off-line next week)
~Toni