boolean switch

Hi All,

I am interested in how those of you who are python coders handle toggling booleans values.

The problem I have been running into a lot recently is I have a boolean property I wish to switch on and off with the same input.
Obviously what happens is that the property flicks between the on and off state as the script is run.

Is there a simple/standard way to handle these situations?

Note that I am using inputs that cannot use the ‘Tap’ feature.


Depends a lot, the most simple/standard way to do it is to simply only toggle it once :stuck_out_tongue: Of course how you gonna do this will depend on what input you have. Something changed between before and after the toggle, you just need to check for that and include it in your input.

If you wanna be lazy you could just set a second bool variable at the same time as the first. And you check if the second variable is unset before setting the first. So it would only toggle once. Then you reset the second depending on whatever you want to do with it.

I don’t know if there’s a way to do it in Python, but when using logic bricks you can accomplish this easily with the property actuator. Assuming your property is called “propertyname”, you can flip the value by setting its value to !propertyname with the actuator.