toggle boolean property with python

Hey. so im making a game and i was wondering if there is a way to detect a button press in python and then toggle a boolean property on several objects as a result. i already tried doing it with logic bricks but the result was very buggy… i would greatly appreciate some help :3

what is the relationship?

keys and doors, or ???

if sensor.positive:
    for child in object.childrenRecursive:
        if 'property' in child:
            if child['property']==False:
                child['property']= True
            else:
                child['property']= False



parenting / child objects is a way to go

sending a message is another

setting the prop directly via python is another

what are you trying to achieve?

you may need a timer or a and/nand system

For toggling bool you can save a few lines with:

child['property'] = not child['property']

Or the confusing alternative:

child['property'] ^= True

Have fun and stuff

1 Like

yeah
mybool = not mybool #probably easiest

also:
mybool = mybool == False

#should work too, if mybool is False then False == False is True. if mybool = True, then True == False is False

I would like to know why you think you need to spread the same data over many objects?

thanks for your help guys it worked :3