Consecutive timer expiration check failing (SOLVED)

Started by Mr Games, Tue 11/12/2018 14:12:56

Previous topic - Next topic

Mr Games

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

// 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!

Khris

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.

Cassiebsg

#2
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

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!
There are those who believe that life here began out there...

Mr Games

Ah, a rudimentary error! Thank you both, "else if" fixed it.

SMF spam blocked by CleanTalk