I am trying to make a script I have written run only once, at the start of the game. However, the standard method I found online of making an always actuator with positive pulse mode turned off is not working for me- the script runs with every frame. I am running Blender 2.45 on a Mac OS 10.4.11. Any ideas?
(Also, it really should mention somewhere in the GameLogic API that properties are stored in the objects under Object.PropertyName. Its reasonable, intuitive, and not there. I found it in a random tutorial for some other subject… anyhow, sorry about the rant.)
Well, I did have one thing pressed wrong (silly error on my part, I’m very sorry). However, I still have some interesting behavior going on:
When the always without positive pulse is hooked up to a script, the script fires once, as it should, but when it is hooked up to an and controller, and that hooked up to a motion actuator (linear velocity with add turned on), the motion controller fires repeatedly.
I suppose my original question is answered, but is this a quirk with the motion actuator?
EDIT: After giving this further thought, I realized that this is exactly how the Always Sensor is supposed to work. It is always on, so it never fires a negative (off) pulse. This is not a bug as I originally suggested, so I will not be reporting it on the tracker or notifying Ben. The proper use of an Always Sensor with Positive Pulse (TRUE Level Triggering) turned off is to fire only one positive pulse.
Also, with any other sensor, a Python script should be expected to run twice, since it runs on both the positive (on) and negative (off) pulse. If you need it to only run once with any sensor other than Always, you must use the isPositive() method in the script to test the sensor’s state.
My original post follows:
I’ve tested this on Blender 2.44 on Linux and the Windows 2.46 RC1 (official) and Ben’s game engine RC5, and you are correct that Python scripts are firing only once and the motion actuator is getting stuck in “On Mode” when hooked to this type of Always Sensor. However, the Python script should be firing two pulses (see the long answer below), so this suggested to me that the Always Sensor is not correctly firing it’s negative pulse, which would be a bug. I tested this in Python, and was able to confirm my suspicion. The Always Sensor is not firing negative pulses at all. This problem still exists in the most recent test builds of 2.46, so I will report this bug on the tracker and notify Ben by forum PM.
Each sensor fires two pulses, a positive pulse when it is activated, and a negative pulse when it is deactivated. (If a pulse mode is selected, then the selected pulse is fired once every logic tic as long as the sensor is active.) If you use a Keyboard Sensor, for example, the sensor fires a positive pulse when the key is pressed, then when the key is released, it fires a negative pulse. The AND controller simply passes this pulse to whatever actuator it is connected to. When the Motion Actuator receives a positive pulse it turns on, and it stays on until it receives a negative pulse. So it would seem in this case (since the actuator is not turning off) that the Always Sensor is not properly firing its negative pulse.
The AND controller passes pulses as positive and negative, but Python scripts simply receive the pulse and run the script regardless of the pulse’s state. (If you only want your script to run only on the positive pulse, you must use the isPositive() function.) Since this is the case, you would expect the following behavior:
would result in the property prop having a value of 1, because the Property Actuator only executes when it receives a positive pulse. This is the result, since the positive pulse of the Always sensor is working correctly.
On the other hand, you would expect this logic setup:
to result in <i>prop</i> having a value of 2, since the script should run on both the positive and negative pulses. This is not the case, however. Instead, <i>prop</i> has a value of 1, indicating that the script is only receiving one pulse (the positive pulse).