In my game i got 10 different objects(players and AI) that can spawn missiles.
Player 1 should not be able to get hit by his own missile, and the same for other players.
Instead of having 10 missiles on layer 2 to spawn in, one for each player with property ‘player1’, ‘player2’ etc to test on,
I thought if is was possible to set a property on an object at spawn time, so each player can spawn in the same missile object and attach a unique identifier on it, something like
The above creates a property on the missile equal to the value in owner property ID, eg. player3
Then i just test for a collision with property player3, and it works.
What if i wanted a value on it as well, maybe to have a damage value to it.
and to further simplify, if you aren’t tied to the idea of object id’s, you can just do something like:
bullet['shooter'] = own
That way if you ever need to reference the shooter object from somewhere else, you do not have to worry about lookup logic to convert the ID to an object. Now the collision property could be something like ‘health’, and then to check whether you are shooting yourself, you just do something like:
shooter = bullet['shooter']
target = cont.sensors['Collision'].hitObject
if not shooter == target:
target['health'] -= bullet['damage']
Or, is it “just” having a basic understanding of how python works that does it? I mean, even someone that knows python well, wouldnt know the code you wrote will add a property in blender.
In the futura, if i need to do something else with addObject, or something else for that matter. Where would i go about looking?
Unfortunately, you just sorta have to feel your way through it (or atleast that’s my general method). There is no official place to go find useful conceptual stuff like that. Some of it is eluded to in the api reference, some is squirreled away in obscure parts of the wiki, some in posts on this and other forums, but none of these is comprehensive.
As a matter of fact, the collision sensor is considered a touch sensor by BGE, and this is not documented in the API Reference. I just sorta guessed that it would have a .hitObject property because touch and ray sensors do.
Learning the correspondence between what you see in the blender UI, and the python representation at BGE runtime feels (to me) like being the main character in a Dan Brown novel.
I kind of miss the possibilities that would show up when using c++, or was it in lua back when i made some add ons for WoW.
Anyway, that was awsome - when i wrote the code, a list of possible properties would show up, along with a short description.
I miss that in python.
I agree there is no real clear documentation that tells you that this object is a container of properties. The access is dictionary-like with the property name as key. But you can see it in the provided examples.