I have been trying to make a script work for some time now, but I was completely unable to see what was wrong in it, then I’ve made a couple of prints…
It seems assigning a value to a bool property directly in a script doesn’t have any effect. I’ve been assigning values to timers, ints, … but bools don’t change. I just replaced my expression by a property actuator, and now it works.
In scripts, you must use numbers instead of the values “True” and “False”. For example, myBool is a boolean property on the owner in this script:
### Simple Switch Script ###
# If "myBool" is True, set it to False
# otherwise, it is False, so set it to True
cont = GameLogic.getCurrentController()
own = cont.getOwner
if own.myBool == 1:
own.myBool = 0
else:
own.myBool = 1
You can work around this by giving values to “True” and “False” in your script:
### Simple Switch Script ###
# If "myBool" is True, set it to False
# otherwise, it is False, so set it to True
cont = GameLogic.getCurrentController()
own = cont.getOwner
TRUE = 1
FALSE = 0
if own.myBool == TRUE:
own.myBool = FALSE
else:
own.myBool = TRUE
Don’t worry. Most people don’t know that. It took me quite a while to figure it out. I had resorted to using Int properties whenever I needed to alter them with a script for quite a while.