Python to play actions

I have a somewhat strange question, but I do have a reason for wanting to know it. I was wondering how you would get an action to play using Python. The reason I ask is because the enemy AI I have set up is kinda messy and not very easy to make additions/alterations to.

For example, if the enemy’s health is high and he gets hit, it plays a certain animation, but if it’s low it plays something different. I was thinking of something like “if health ==25:” but then I don’t know what to put after it. I’m probably not explaining this super well.

I did see a post about this on here, but they were using 2.5 and I have 2.49b so I couldn’t open their file to see what they did.

If anyone knows how to do this, please let me know. It’s probably really simple, but I don’t know too much about Python.

Connect an action actuator to your script.

action = own.actuators['Action']
if health == 25:
    action.action = 'action name here'

own is the armature playing the animation, cont is the python controller. Hope that helps, but it might need a few adjustments.

That does help actually. cont.activate to start it and cont.deactivate to end it. Now another question. How would I set it as an interval, like if health is between 25 and 50:

replace ‘if health == 25:’ with ‘if health > 25 and health < 50:’.