actions and layers in bge I am using a script to decide which animation my player will run, based on if he holds a flashlight or not. All the actions can be seen in the following image. The actions's layers start from 0 and reach 7.



Here is the script I use to define which animation should play and when.



Everything works, except from the fact that when game starts and the player is still with no flashlight in his hands, he uses the "stand_f" action while he should have used the "stand_no_f". Also there is some visible lag sometimes when changing from one action to the other.

I think these problems connect to the layers somehow, since if I change "stand_no_f" action's layer to 8 instead of 0, now the correct action happens when he is still with no flashlight, but every other action stops happening or lags indefinitely.

So any ideas why the first action is wrong or why there is a random tiny lag between changes of actions?

P.S. the file is big to share and all the scripts are external that is why I did not share in the first place. Also I use a script to define sensors/conts/acts.
Your logic cares keyboard sensors only. 

You need to describe and handle a "at startup" event. This is typically triggered via an always sensor.