[Bf-committers] GE object instances Id?

Campbell Barton ideasman42 at gmail.com
Fri Mar 13 09:01:01 CET 2009


On Fri, Mar 13, 2009 at 3:51 AM, Natanael Olaiz <nolaiz at gmail.com> wrote:
> Hi,
>
> First: thanks to all for your answers.
>
> El 03/12/2009 09:39 PM, Toni Alatalo escribió:
>> Mitchell Stokes kirjoitti:
>>
>>> All instances of game objects that are made from the same blender
>>> object, and yes
>>>
>>
>> .. "have the same name", i guess you meant to continue there.
>>
>> indeed i didn't realize this talk was about the instancing during the
>> running of the game, was just thinking of objects that have already been
>> put to a scene on the modelling side before the game is started - those
>> all have unique names.
>>
>
> Yes, that is my question. Let me try to explain a little better with an
> example:
>
> The first level ("level_1_home") have some rats. For instance, at
> [2.67,21.97,3.97] there is a "rat.010" object, and at [4.21,22.15,3.97]
> there is a "rat.011".
> If I put an "allways" sensor on rat and rig_rat on "sheep.blend" file
> library, triggering a Python script with a "print
> GameLogic.getCurrentController().getOwner().name", I obtain on every
> rat: "OBrat", even from the "level_1_home" instantiations of that model.
>
> I tried now putting the script on the level, on each object and it works
> OK (it says rat.010 and rat.011)....
> But... can I get the instance name (rat.010 / rat.011) from a script
> within the main library? or I need to duplicate the script on every
> instance by hand?
>
>
>>> Yes and no. If I understand you right, you want to do something like,
>>> "if object a is a sheep, do this". (...)
>>> own = GameLogic.getCurrentController().getOwner()
>>> if hasattr(own, "sheep"):
>>>     print "I'm a sheep!"
>>> On Thu, Mar 12, 2009 at 11:08 AM, Natanael Olaiz <nolaiz at gmail.com
>>> <mailto:nolaiz at gmail.com>> wrote:
>>>
>>>     I have a question about the Game Engine: there is a way to identify
>>>     between different objects of the same type?
>>>
>>>
>>
>> that case of 'if is sheep' etc. i would call "identify the types of
>> different objects", not "identify different objects of same type", but
>> perhaps am just used to a bit different terminology than Natanael :) ..
>> the solution with properties is indeed nice for such typing if that was
>> your need (identifying type and not an individual instance, in my / oo
>> programming terminology).
>>
>>
>>>     BTW, I don't know if this is the proper list to ask this question. If
>>>     not, please tell me where I have to ask...
>>>
>>>
>>
>> forgot to mention in the earlier quick reply that usually these usage
>> things are asked on the forums, at least some years ago the
>> blenderartists GE forum was really active and helpful, ppl knowing all
>> sorts of tricks and hacks to weird problems even.
>>
>> but i guess this kind of talk about IDs perhaps the least off topic kind
>> of talk on the coders list :)
>>
>>
>
> Good to know that. Thanks!!
>
>
> Best regards,
> Natanael.*
> *
>
>>>     Natanael.
>>>
>>>
>>
>> ~Toni
>>
>> _______________________________________________
>> Bf-committers mailing list
>> Bf-committers at blender.org
>> http://lists.blender.org/mailman/listinfo/bf-committers
>>
>>
>
> _______________________________________________
> Bf-committers mailing list
> Bf-committers at blender.org
> http://lists.blender.org/mailman/listinfo/bf-committer
>

excuse the brief reply,
- fairly sure there is no way to reference the empty that instances
groups in the BGE. (benoit will know)
- In YoFrankie Rat/Sheep/Ram all use the same logic base object. You
can tell which is which by the 'type' property - will be one of
shp/ram/rat
- In YF they each have a unique 'id' int property that should stay the
same while the level runs.
- if you want a unique value for the KX_GameObject use
hash(GameLogic.getCurrentController().getOwner()) - This uses the
memory address of the class.

-- 
- Campbell


More information about the Bf-committers mailing list