Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: idiotbox on Sat 29/10/2005 21:35:24

Title: Problem with on_key_press
Post by: idiotbox on Sat 29/10/2005 21:35:24
My character has a knife and I want him to strike continuously if the key is held down, but there should be a second or so in between each strike. The character just strikes repeatedly and ends up stuck in the striking position if I hold the key down. It would be even better if I could only make him strike once, even if the key is held down. Is there any way to do this?
Title: Re: Problem with on_key_press
Post by: Ashen on Sun 30/10/2005 23:31:06
You should be able to use the Character.Animating property to stop it sticking.
E.g.:

if (keycode == 32) {
  if (cEgo.Animating == false) { // character isn't animating
    cEgo.Animate (2,3,eOnce); // or whatever
  }
}

Will mean that the character will keep playing the animation as long as the key is pressed - but will play it all the way through. To add a delay between it playing - or to make it only play once - I think you'll have to use variables and Timers.
E.g.

//on_key_press
if (keycode == 32) {
  if (canplay == 0) {
    cEgo.Animate (2,3,eOnce); // or whatever
    canplay = 1;
    SetTimer (1, 40); // If you want the delay version
  }
}

// repeatedly_execute
if (IsTimerExpired (1)) canplay = 0; // Obviously, for the delay
// or
if (IsKeyPressed (32) == 0) canplay = 0; // to play once, even if key is held down

Title: Re: Problem with on_key_press
Post by: idiotbox on Mon 31/10/2005 00:10:00
Hm, well that works, thanks! but the only issue is that the character strikes in the direction he is facing. So I suppose I could throw in an "if" for each direction he faces as well, because otherwise he would only strike in one direction.
Title: Re: Problem with on_key_press
Post by: Ashen on Mon 31/10/2005 00:19:43
Character.Loop (http://www.adventuregamestudio.co.uk/manual/Character.Loop.htm). Should stay the same when you change views for the animation, so you could do:
cEgo.Animate(cEgo.Loop, 3);

(If you're using un-used loops in the same view, you could do cEgo.Loop+8, or whatever.)

Side note:
Please read through the manual, or at least the index. The last few questions you've asked are pretty much directly answered by just reading the manual, and being familar with the various Character, Object, GUI and GUI Control properties.