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
$\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$
  • $\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 '15 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 '15 at 9:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.