Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Mr Games on Tue 11/12/2018 14:12:56

Title: Consecutive timer expiration check failing (SOLVED)
Post by: Mr Games on Tue 11/12/2018 14:12:56
Hi everyone


I've started a mini "boss fight" where clicking on the Succubus causes her to "teleport" (with object.SetPosition) but for every instance there is a timer. If any of these timers expire the player is sent to room 38 (game over.)


I'm stumped because the first timer is working, but after the initial click (which I intended to stop the first timer and start the second) nothing happens. Here is my code:




Code (ags) Select

// room script file


Timer *succubTimer0;
Timer *succubTimer1;
Timer *succubTimer2;


int showdown = 0;


function room_AfterFadeIn()
{
  succubTimer0 = Timer.StartRT(3.0);
}


function room_RepExec()
{
  if (Timer.IsExpired(succubTimer0)) {
  cSmileyface.ChangeRoom(38);}
  if (Timer.IsExpired(succubTimer1)) {
  cSmileyface.ChangeRoom(38);}
}


function oSuccubus_AnyClick()
{
  if (showdown == 0) {
  Timer.Stop(succubTimer0);
  oSuccubus.SetPosition(1528, 407);
  showdown += 1;
  succubTimer1 = Timer.StartRT(2.0);}
  if (showdown == 1) {
  Timer.Stop(succubTimer1);}
}



Apologies in advance for being a total noob. I'm learning all the time!
Title: Re: Consecutive timer expiration check failing
Post by: Khris on Tue 11/12/2018 14:39:15
The two if blocks at the end will both run on the first click, since you are setting showdown to 1, but then don't exit the function and don't use else which means the next block will run right away.
Title: Re: Consecutive timer expiration check failing
Post by: Cassiebsg on Tue 11/12/2018 14:43:39
Well, I can't say if anything else is wrong with your code, but right after you set showdown+=1 and then start the timer 1, you check if the showdown==1, which it is, since you just set it and then you stop the timer. So I would say that explains why it's not working.

Try puting an else if for showdown==1.

Code (ags) Select

else if (showdown == 1)               // Here is where I changed your code
{
Timer.Stop(succubTimer1);
}


PS . Khris was faster than me... I'll just post it anyway just in case...

EDIT 2: Uhm, AGA fix the code!
Title: Re: Consecutive timer expiration check failing
Post by: Mr Games on Tue 11/12/2018 15:04:35
Ah, a rudimentary error! Thank you both, "else if" fixed it.