i'm using on_key_press to animate a character in my game but i only want the action to happen once and not to happen again once i release the key (it's causing problems with the footstep sound being played repeatedly until the sound engine crashes)
i'm using this code in the room script
function on_key_press(int keycode){
Ã, if (keycode=='UP') cEGO.Animate(0, 0,eOnce,eNoBlock);
UP isn't the actual key i'm using but the game is for OROW and i don't want to give too many hints away.
any help will be greatly appreciated
Use the character.Animating flag to check whether the character is currently (already) animating.
Something like this should work:
if ( keycode == 'UP' && !cEGO.Animating )
cEGO.Animate ( 0, 0, eOnce, eNoBlock );
that's fixed the problem of it repeating before the animation has finished but it's added a new problem, i now can't trigger the action again until the animation has stopped and i've had to put a delay in the last frame of the view to stop it repeating too quickly again.
one way to describe what i want to do is comparing to the use key in DOOM, pressing it will activate a switch or door once even if you keep the button pressed, but if you wanted you could keep pressing the use key which would trigger the door again even if it hadn't finished opening/closing.
You could use a variable, and IsKeyPressed(), e.g.:
// on_key_press:
if (keycode == 'UP' && UpPressed == 0) {
//Do stuff
UpPressed = 1;
}
//repeatedly_execute(_always)
if (UpPressed == 1 && IsKeyPressed('UP') == 0) UpPressed = 0;