Action in python 2

Hey,
My current script I’ve made is this:

cont = GameLogic.getCurrentController()
own = cont.getOwner()

import GameKeys

keys = cont.getSensor(“run”)
run = cont.getActuator(“Run”)

wKey = GameKeys.WKEY

if keys.getKeyStatus(wKey) == 1:
run, reset=True

GameLogic.addActiveActuator(run, True)

When I press Wkey the action starts, but doesn’t stopwhen key is released. :confused:
How can I make this?

I know I should probably use Inv (invert) for the W key. But I don’t want to add another Sensor for that. :spin:

Thanks :eyebrowlift2:

Check for a released wkey and then deactivate the actutor.
hints:

Can’t find it. o.0

Plz help :stuck_out_tongue:


cont = GameLogic.getCurrentController()
own = cont.getOwner()

import GameKeys

keys = cont.getSensor("run")
run = cont.getActuator("Run")

wKey = GameKeys.WKEY

if keys.getKeyStatus(wKey) == 1:
run, reset=True
GameLogic.addActiveActuator(run, True) 
else:
GameLogic.addActiveActuator(run, False) 

Did you tested it? Doesn’t work with me. =[

edited last post

Don’t use just else as in this case the key status can be one of KX_INPUT_NONE, KX_INPUT_ACTIVE, KX_INPUT_JUST_RELEASED. You said you need to know when the key is released which is KX_INPUT_JUST_RELEASED. Otherwise the actuator will be deactivated 1 logic frame after pressing or releasing the wkey.

Damn, I suck at python. xD

All i’ve got so far is this:

cont = GameLogic.getCurrentController()
own = cont.getOwner()

import GameKeys

keys = cont.getSensor(“run”)
run = cont.getActuator(“Run”)

wKey = GameKeys.WKEY

if keys.getKeyStatus(wKey) == GameLogic.KX_INPUT_JUST_ACTIVATED:
run, reset=True
GameLogic.addActiveActuator(run, True)

if keys.getKeyStatus(wKey) == GameLogic.KX_INPUT_JUST_RELEASED:
GameLogic.addActiveActuator(run, False)

The problem with that is that what if he has more running buttons? For example W, A, S, D, which is where I’m guessing the buttons are… I don’t want to double my if statesments… Also, else does it if the ifs above it arn’t active and it’s more secure… You can also use the KX_INPIUT_NONE, but I like to use the else… But better yet…

cont = GameLogic.getCurrentController()
own = cont.getOwner()


import GameKeys

running = 0
keys = cont.getSensor("run")
run = cont.getActuator("Run")


wKey = GameKeys.WKEY
aKey = GameKeys.AKEY

if keys.getKeyStatus(wKey) == GameLogic.KX_INPUT_JUST_ACTIVATED:
run, reset=True
running = 1
elif keys.getKeyStatus(aKey) == GameLogic.KX_INPUT_JUST_ACTIVATED:
run, reset = True
running = 1


if running == 1:
GameLogic.addActiveActuator(run, True)
else:
GameLogic.addActiveActuator(run, False)

This way if he has more actuators and more keys to press, he can turn them off all at the same time… I don’t know if he wants to add more buttons, but your way is better if he only has one button, maybe it’s better with more, I’m still learning python :slight_smile:

gamemaster,

your script is fine when you remove this line:

run, reset=True

I do not know why you have it there as reset is not used anywere and run is your actuator.

By the way have you set your action actuator to “Loop Stop”? Otherwise the actuator will play the complete action regardless of the activation state.

Hey, thanks a lot for your help man. :slight_smile:
There is only one more problem… Sorry I’m such a pain in the az. x’D

When I press W key, It walks nice… But when I hold W key, and press another one at a time… He stops the animation.

Plz help me :stuck_out_tongue: