setActionframe Problem.

In blender game python as you can see here,
http://www.blender.org/api/blender_python_api_2_62_3/bge.types.html#bge.types.KX_GameObject.setActionFrame
You can set the action frame to whatever number, but my problem is… how do you specify the action? Like, it says,
" setActionframe(frame, layer=0) "

But it says set action… but how do I make it set a specific action? It would’ve been nice if it was something like,

" setActionframe([‘ActionName’]frane, layer=0) "

But it isn’t… and I’m confused! xD I know there is a correct way to do it, I’m just not sure!

So anyone know how it’s properly used to specify an Action?

I haven’t gotten to the point of needing to control actions via python yet but did you try first using playAction()? It has you specify the name and the layer to play on.

playAction(name, start_frame, end_frame, layer=0, priority=0, blendin=0, play_mode=ACT_MODE_PLAY, layer_weight=0.0, ipo_flags=0, speed=1.0)

Yes, I’ve tried PlayAction and it works fine for me! What I’m trying to do is set a certain actions frame though, like if I wanted to do something like,

Rotation = own[“Rotation”]
Position = own[“Position”]
if Position > 12:
setActionframe(Rotation + 12, 0)

Now my problem there is I am not setting any specific action’s frame, and I want it to set a specific action’s frame.

If the animation has not been played first via playAction, or has finished playing, then setActionFrame will not work. (Check isActionPlaying to see if the animation is still considered active)

I took into account your suggesting and this is what I have come up with,

if wKey.positive:
own.playAction(“walk”, 5, 25, 0, 0, 3, bge.logic.KX_ACTION_MODE_LOOP)
own.setActionframe(8, 0)

What it should be doing is keeping the action “walk” at frame 8. And I put the setActionframe after the playAction… yet it still doesn’t work, the whole animation frames 5 - 25 plays and isn’t held at frame 8 like it should be.

I suspect I’ve typed something wrong, or misplaced some variables or have the wrong action mode or something.

The current implementation of playing actions is kind of finicky, though there are ways you can go about getting the result you’re looking for.

  1. Use an Action Actuator in property mode.

It’s not as flexible as a pure Python solution, but will get the job done in most cases.

  1. Call playAction() with a very low speed value.

Unfortunately playAction() doesn’t work if you set the play speed to 0. Using a very small speed value gets around this while keeping the automatic action updates negligible.

  1. Call playAction(), then call stopAction() whenever you have a logic tick that you don’t call setActionFrame() on.

Calling stopAction() will prevent any more automatic updates to the current action’s frame. However since action updates occur after logic updates, you have wait until the logic tick after your last call to setActionFrame()/playAction() to call stopAction(). Otherwise you won’t see the most recent update to the action frame.

Property mode has worked for me,

stopAction() sounds handy though as actions never seem to deactivate unless I kill them with python,

I dont quite understand how to play a action one time and have it die on the last frame… (play mode?) loop end?

I guess I’ll go with Option one, I figured this would be the way to go in the first place, though I wondered if there was a pure python way to do it! Thanks for making it clear! :smiley:

Play mode works for me the best.