Playing an action once when sensor is True

I want to play an action once.

I use KX_ACTIONACT_PLAY and then create an action and specify all parameters, attach my script, and set the sensor to true pulse.

The result is that my armature will just play the animation endlessly rather than stopping.

Here’s the code:

import bge, bge.logic as gl

play = gl.KX_ACTIONACT_PLAY
loop = gl.KX_ACTIONACT_LOOPEND

own = gl.getCurrentController().owner

own.playAction('test', 1, 20, 0, 0, 0, play)

It’s just a simple test code for a simple action.

Is there any way to make it only ever make an action play once with a sensor set to True positive pulse mode? Wasn’t like this in 2.79. I am doing it via Python, not logic bricks.

Using UPBGE 0.36.2 on macOS.

:rofl: … the eternal “True pulse spam mode forever” meme is real … i would never understand why people keep use that “true pulse” like it’s written in marble or something … :face_with_raised_eyebrow:

when your action is done, your sensor will spam him to play the action again. Why would you expect otherwise ? :exploding_head:

What you need in your script (if it’s running on True pulse) is a single event/pulse that will allow your action to be played

if own.sensors['my_sensor'].status == 1  : own.playAction('test', 1, 20, 0, 0, 0, play)

Either way , you can put that playAction in a specific code that is not running all the time

Well, you can just use a simple flag to do this. A flag is just a boolean variable/property that you can enable/disable to have more control about specific things in your game. If you use the sensor status, be careful with unwanted behavior, because if you change the object’s state to another, and then return it to the previous state, your script will run again because the sensor will be reactivated, causing it to run your script again.

And you shouldn’t use “KX_ACTIONACT_PLAY” with the “playAction” python function, because “ACTIONACT” is for actuators. You can use “KX_ACTION_MODE_PLAY” instead. I’ll drop the API links so you can see all the options:

actuators: https://upbge.org/docs/latest/api/bge.logic.html#action-actuator
playAction: https://upbge.org/docs/latest/api/bge.logic.html#kx-gameobject