Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: barefoot on Sun 09/01/2011 05:42:21

Title: SOLVED: IsTimerExpired extented int options
Post by: barefoot on Sun 09/01/2011 05:42:21
Hi

I have not found a suitable answer to my query about int options:

It works but would like more that just 1 Say command.



function room_RepExec()
{


 if (IsTimerExpired(1) == 1) {
  int ran=Random(2);
   if (ran == 0)
   cdiablo2.Say("You've got the wrong man!");
 
  // Something here like another char speaks
   
     else if (ran == 1)cdiablo2.Say("I'm innocent!");

// Something here like another char speaks

      else if (ran == 2) cdiablo2.Say("I'm missing my break time!") ;

// Something here like another char speaks

       SetTimer(1, 160);

}
}


Grateful for any assistance

barefoot






Title: Re: IsTimerExpired extented int options
Post by: Calin Leafshade on Sun 09/01/2011 05:55:39
Just like any other if statement



if (ran == 1) {

    DoThis();
    AndThis();

}
else if (ran == 2) {

    DoThisInstead();
    ThenThis();

}
Title: Re: IsTimerExpired extented int options
Post by: barefoot on Sun 09/01/2011 05:57:27
Hi

I've scored with this using the old &&:


function room_RepExec()
{


  if (IsTimerExpired(1) == 1) {
   int ran=Random(2);
    if (ran == 0)cdiablo2.Say("You've got the wrong man!")&& cleech.Say("Poppycock!");
     else if (ran == 1)cdiablo2.Say("I'm innocent!") &&  cleech.Say("You're as guilty as Manson!");
      else if (ran == 2) cdiablo2.Say("I'm missing my break time!")&& cleech.Say("That's such a pity!");
       SetTimer(1, 120);

}
}


Just seen your reply thanks Calin

barefoot

Title: Re: SOLVED: IsTimerExpired extented int options
Post by: Calin Leafshade on Sun 09/01/2011 06:00:58
using && in that way is very odd.

I suggest doing it the way i suggested.. it far more readable if nothign else.
Title: Re: SOLVED: IsTimerExpired extented int options
Post by: Khris on Sun 09/01/2011 14:40:17
As expected, using && in that really creepy way won't do the trick. It actually compiles, but a) won't if you use e.g. Display instead of Character.Say and b) only runs the first .Say, not the second one.

barefoot, you already know that commands are grouped together by putting them inside { and }, just transfer that knowledge to not just "int options" but every other situation.
Title: SOLVE: IsTimerExpired extented int options... code change
Post by: barefoot on Sun 09/01/2011 16:51:38
Hi Calin/Khris

as suggested:

function room_RepExec()
{
     if (IsTimerExpired(1) == 1) {
     int ran=Random(2);
     
    if (ran == 0) {
     cdiablo2.Say("You've got the wrong man!");
      cleech.Say("Poppycock!");
       cginger.Say("Come clean!");
 
   }
     else if (ran == 1) {
     cdiablo2.Say("I'm innocent!");
      cleech.Say("You're as guilty as Manson!");
       cginger.Say("And Jack the Ripper!");

  }


    else if (ran == 2) {
     cdiablo2.Say("I'm missing my break time!");
      cleech.Say("That's such a pity!");
       cginger.Say("Poor little you!");
   
}
    SetTimer(1, 120);
}
}



Cheers


barefoot




Title: Re: SOLVE: IsTimerExpired extented int options... code change
Post by: Khris on Sun 09/01/2011 17:11:00
And with consistent indentation:

function room_RepExec() {

  if (IsTimerExpired(1) == 1) {

    int ran=Random(2);     

    if (ran == 0) {
      cdiablo2.Say("You've got the wrong man!");
      cleech.Say("Poppycock!");
      cginger.Say("Come clean!");
    }
    else if (ran == 1) {
      cdiablo2.Say("I'm innocent!");
      cleech.Say("You're as guilty as Manson!");
      cginger.Say("And Jack the Ripper!");
    }
    else if (ran == 2) {
      cdiablo2.Say("I'm missing my break time!");
      cleech.Say("That's such a pity!");
      cginger.Say("Poor little you!"); 
    }

    SetTimer(1, 120);
  }
}


The difference in readability is worth the extra few seconds this might take, AGS will do this style of indentation automatically though.