Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: deltree on Mon 02/05/2005 12:31:03

Title: [SOLVED]problem with code (timer and keypresssed)
Post by: deltree on Mon 02/05/2005 12:31:03
hi,
I've got a problem with this code: (repeatedly execute)

if (IsKeyPressed(32)==1 && IsTimerExpired(2)==1) {
   SetTimer(2,40); //can't redo before 1 second
   PlaySound(5);
}

It is supposed to play a sound everytime you press "space", and it waits 1 second before you can press space again.
the problem is : it doesn't work. the sound doesn't play. however, I'm sure the sound plays in normal code.
the timer is already set in "player enters screen(after fadeout)" interaction code.
do you see what the problem is?
thanx
Title: Re: problem with code (timer and keypresssed)
Post by: Ashen on Mon 02/05/2005 12:52:39
According to the manual, IsTimerExpired() only returns 1 as the timer expires. So, unless you're pressing space at exactly that moment, the condition is never true and the sound never plays.
You might have to do something like:


int count;

//then, in rep_ex:

if (IsKeyPressed (32) && count == 0) {
  PlaySound (5);
  SetTimer (2, 40);
  count = 1;
}

if (IsTimerExpired (2)) count = 0;
Title: Re: problem with code (timer and keypresssed)
Post by: deltree on Mon 02/05/2005 13:23:41
thanx,
I though it could be something like that.