How to set a property of a different object

Hi, I have a python script running on an empty and want to change a Bool property of a different object in the python script. How can I change the Boolean state from True to False or the other way around?

Thanks for your help


scene = GameLogic.getCurrentScene().getObjectList()

# Let's assume the second (or as you call it; "different") object is named "Cube":
secobj_own = scene["OBCube"]
secobj_own.boolvarname = 1 # <- for true, 0 for false.

Thanks.

I’ve another question.
How can I set the visibility on / off also in python when the script is linked at another object

One of two ways (that I know of):

  • Select both the script running object (object A), and the object whose visibility you want to control (object B). With both of them selected, you’ll be able to tie the visibility actuator brick of object B to the script controller brick of object A. Then you can just control the visibility of object B, the same way you would control the visibility of object A.
  • You set a boolean property on object B, and you have that property control the visibility actuator. Then you can access and modify that property as I demonstrated above.

Ahh thanks very much (I chose the second way)

When I turn the objects invisible it works, but if i want to make them visible it does not work anymore. Any idea why?

http://socialstorage.googlepages.com/helpChill.blend

Script runs on camera -> controls visibility actuators on cube.
Run with [P], press [Space] to toggle visibility.

Ahh thanks :wink:

I forgot to add a second visibility actuator

lol, been there done that too.

Good details Social, thanks.