0
$\begingroup$

The question explains itself. I have a property in one script and another property in another script. I am not sure how to define the python scripts in the blender game engine. How can I get a property from a different script in the game engine?

$\endgroup$

1 Answer 1

1
$\begingroup$

Properties belong to game objects rather than Python code.

You write a property with myGameObject[propertyName] = value

example:

hitObject = sensor.hitObject
hitObject["detected"] = True

You read a property with value = myGameObject[propertyName].

example:

hitObject = sensor.hitObject
wasAlreadyDetected = hitObject["detected"]

I hope it helps

$\endgroup$
2
  • $\begingroup$ So, if properties belong to game objects, when would I use properties in python code? Also, thanks for the answer! ;) $\endgroup$
    – blackhole
    Dec 7, 2015 at 22:01
  • $\begingroup$ I may misunderstand you, but you use properties when you want to store data at a specific object. Your python code lives as long as the code gets executed. That means all variables will die after exiting the python controllers execution. When you store values in a property you can access it from a different Python controller execution either from same or from other object. $\endgroup$
    – Monster
    Dec 9, 2015 at 9:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .