SOLVED: IsTimerExpired extented int options

Started by barefoot, Sun 09/01/2011 05:42:21

Previous topic - Next topic

barefoot

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.

Code: ags


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






I May Not Be Perfect but I Have A Big Heart ..

Calin Leafshade

Just like any other if statement

Code: ags


if (ran == 1) {

    DoThis();
    AndThis();

}
else if (ran == 2) {

    DoThisInstead();
    ThenThis();

}

barefoot

Hi

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

Code: ags

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

I May Not Be Perfect but I Have A Big Heart ..

Calin Leafshade

using && in that way is very odd.

I suggest doing it the way i suggested.. it far more readable if nothign else.

Khris

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.

barefoot

Code: ags
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




I May Not Be Perfect but I Have A Big Heart ..

Khris

And with consistent indentation:

Code: ags
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.

SMF spam blocked by CleanTalk