with the recent additions to the sensor logic brick, I thought it might be a good idea to write a documentation regarding pulses. It could be helpful when designing the logic of a game. It is also a good source to check for performance gaps.
Hey, thanks:yes: alot Monster, that looks very informative, going to take a read of it. Thanks for taking the time to write that man. Also, on this forum I’ve come across many of your thorough responses and blend files with solutions to problems I had, and they’ve helped me alot.
Thanks for being so generous and thoughtful, take care n God bless!
Peter.
Pulses are used by the standard controllers (AND,OR etc.) to deactivate the connected actuators. E.g. an animation plays (IPO/action in loop stop mode, or motion actuator) as long as you hold a key.
Press key -> True pulse -> activate actuator
Hold key -> no pulse -> actuator still active
Release key -> False pulse -> deactivate actuator
No key -> no pulse -> activator still deactivated
There is no need to use the True or False pulse modes as the actuators remain active/inactive.
You enable Inv and get the opposite - the animation playes when you NOT press the key.
You enable Tap and you get a one frame animation as the actuator is stopped one logic tick after activation. That could be usefull for stepping e.g you press a key the object makes one step, you press it again = another step etc…
The pulse modes (True/False) are special handy in combination with scripts. As you see the controllers are triggered only when the sensor state changes. The actuators do their work without the controllers as long as they are active. The script controller will run only when the sensor changes from False to True and True to False. This makes exactly 2 script executions. As long as you just activate/deactivate actuators this is fine. But script controllers can also behave like actuators and need pulses for execution.
In a lot of cases you want to execute the script every time the sensor is True. So you activate the True pulse mode -> The script is executed every time as long as the sensor is True.
Example: When holding a key the object should copy the rotation of another object.
The opposite is that you might want to execute the script as long as the sensor is False. Example:
When not holding a key the object should copy the location of another object.
You can argument, that you can achieve this with a combination of other sensors or even with an always sensor in True pulse mode. This is right there are multiple ways.
From logical perspective it is important to understand why a controller is executed and (much more important) why it is not executed. You wonder why your script is not working? Check when it is activated (print can help). You wonder why your script is executed twice but you expect just one run? Beside the True pulse there is always a False pulse (except use the always sensor or you reset the sensor).
From performance perspective a controller should only be executed if it is necessary. Each execution eats time from the logic execution. If the controller does not change anything it is a waste of performance. There were some threads with blends that had bad performance, because they set the same scene again and again at each logic tick etc…
I was pondering this morning about this very topic… I wonder, is it possible to find out using python which controller sent the pulse? This would be useful for me so I don’t have to split the update script from the controlling when creating click-able lists.
-edit-
D’oh! Sorry… Followed a link and forgot to read the last post date ):