Obtaining properties from another object


Who knows how to get properties from another object when the sensor “ray” is active?



In the process of producing my little game, I was faced with the inconvenience - many logical bricks and not universality. For example, near each button there is a lamp and a plane with a glow, and to them one must constantly attach logical bricks … And so, put the lamp near the button, the script took from the button properties - everything would be easier. And a lot of light sources in the game scene, even in the off state (energy - 0), take their resources. And so to set the movement of one lamp to different objects, and there the script will take the necessary properties. I’m just trying to optimize everything on the example of my game, then I will share a lesson.

Thank you for attention.

With the help of Nicholas_A, the issue is resolved.
Here is a working example with optimization - to change the color of the object, there is no need for animation, or/and unnecessary logical bricks. - example first by reference “WS” - movement
And the example for which the question was asked - example second by reference

scene = logic.getCurrentScene()
prop = scene.objects["Object Name"]["prop name"]
  • did not even have time to lay out, but you already answered … - thank you.Would you please make an example, which I laid out to make a script? I just still have trouble with the python, the frost on my brains prevents me from thinking:D.

here. It may or may not work cause I didn’t test it

get_properties.blend (478 KB)

Working! You did not register the module … but it works. Thank you very much, I’m optimizing my game even better.

  • one more question - get_properties.blend (464 KB) there is a second script that changes colour depending on the property. Why is he working in the “multitexture” mode, and in “GLSL” - no?
    Error in terminal^

Blender Game Engine Started
Python script error - object ‘Cube.003’, controller ‘Python’:
Traceback (most recent call last):
File “/home/user/work/05-examples/01-BGE _example/get_properties.blend/getProperty.py”, line 12, in getProps
TypeError: ‘NoneType’ object is not subscriptable
Python script error - object ‘Cube.003’, controller ‘Python’:
Traceback (most recent call last):
File “/home/user/work/05-examples/01-BGE _example/get_properties.blend/getProperty.py”, line 12, in getProps
TypeError: ‘NoneType’ object is not subscriptable
Blender Game Engine Finished

I kind of understood why the console gave out a error - the sensor “ray” when it hits the void and does not find an object with the property “prop”, as if he understood this as an error.
It seems that in this version without errors, but the object does not want to change the color through the second script, and there are no errors in the console.

from bge import logic

scene = logic.getCurrentScene()

def getProps(cont):
    own = cont.owner
    ray = cont.sensors["Ray"]
    if ray.positive:
        hitObj = ray.hitObject
        own["prop"] = hitObj["prop"]

you can change object color with obj.color

Well man, I already understood it - ticked the “object color” and everything works. Thank you.