Action does not execute inside 'if' block

Hello people.
I am trying to execute an Action inside an ‘if’ block but it is not working. And there is no error on the console.
If I put the execution line outside the ‘if’ block it works normally.
Could someone explain to me why the same code is not working as intended?
Here is the complete script for example:

from bge import logic, events
import bge
cont = logic.getCurrentController()
own = cont.owner

keyboard = logic.keyboard.inputs

own.playAction('verme1', 1, 60, play_mode = logic.KX_ACTION_MODE_PLAY)

if keyboard[events.IKEY].values[-1]:
    own.playAction('verme1', 1, 60, play_mode = logic.KX_ACTION_MODE_PLAY)

i have recreated this and it work just fine ( tested in UPBGE versions 2.23b2 / 2.24 / 0.3 eevee )
here is the blend used.’
action-inside-if.blend (481.8 KB)

if you want to do the same thing in BGE 2.79 and older, then you need to change the code to this.

from bge import logic, events
import bge
cont = logic.getCurrentController()
own = cont.owner

keyboard = logic.keyboard
JUST_ACTIVATED = bge.logic.KX_INPUT_JUST_ACTIVATED

if keyboard.events[events.IKEY] == JUST_ACTIVATED:
    own.playAction('PlaneAction', 1, 60, play_mode = logic.KX_ACTION_MODE_PLAY)
  
1 Like