Having trouble with sensors.

more specific, I’m having trouble with the keyboard sensor.

What I’m trying to do is have something happen only when the key is first pressed down, and only when the key is release then pressed down again.

I think it has to do with true level pulsing and false level pulsing, I read some explanations on that but can’t seem to get it working for me, if it makes any difference I’m using it for a script not through and controllers.

If the script is only connected to the keyboard sensor, then you can just use kbSensor.isPositive() function to detect if the key is pressed or released. As the script runs only at these moments, is it sufficient to distinguish.

If the script is connected to more than one sensor, then you have a problem because the kbSensor.isPositive() will return true while the key is pressed and the script will run more often than at key press/release time.

The solution is to use the new kbSensor.isTriggered() function, which returns true only if the sensor triggered at the current frame (so the correct test is kbSensor.isPositive() && kbSensor.isTriggered()) but I’m not sure if this function is already in 2.47

Otherwise you can do it yourself in python by storing the value of isPositive() and detecting the false-true transitions.

Ok, thanks. isTriggered() isn’t in 2.47 yet.