Always Sensor behavior Python

Hello

Here’s the situation: when I press spacebar, the always sensor will be activated.


Is there a way to avoid this from happening?

Thanks

Change the always sensor to Tap.

The python controller is looking for an input from something, so, because Always is an active input, it will run whenever the object is updated, and keyboard sensors send 2 pulses (key down, key up).

Hey, yes. That works!

This behavior is exactly what you set up. Your expectations do not match the configuration ;). An Always sensor is labeled “Always” because it ALWAYS evaluates true. (Better do not try to change this it will result in confusion)

If your intention is to react on object creation (initial Always trigger) OR on keyboard input (Keyboard press/release trigger) better check both sensors rather than just one.

You’re right. I expected the Always Sensor to be independent from other sensors. I still don’t understand why it activates when other sensors (connected to the same controller) are activated. To me that is confusing.

It is always activated, exactly what it says.

Let me clarify some more:
There are four sensor states: Just activated, activate, just deactivated, not active

We call the ‘just **activated’ ‘pulses’ and they are what cause controllers and actuators to run.
But when a controller is still activated, it doesn’t send these ‘just **activated’ pulses, it just sits their with the state sens.positive = True
Until you release the keyboard where it sends a deactivation pulse, and then sits with sens.positive = False

When you enable Pulse mode (the ‘’’ button), you make it send activation pulses while it’s active, but when pulse is off, it still is in the positive state.

What you may be looking for is the delay sensor. Have it with repeat off, delay 0 duration 1. This will activate for a single pulse and then deactivate. (unlike the always sensor which never deactivates)

No idea how confusing that was…

Oh, now I get it. I thought it was only active on pulses. Never thought about it that way. Thanks, both.

Also thanks for the tip for the delay sensor. I think that will be the solution.

Edit: Yes, it solved my problem.