Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: quixotecoyote on Thu 08/11/2007 08:39:38

Title: SayBackground -- Something clever?
Post by: quixotecoyote on Thu 08/11/2007 08:39:38
This may be old news, but in case it hasn't been said before:

I was trying to get a group of guards to have a looping conversation in the background.  I wanted to be able to interrupt the conversation by speaking and have it resume when I stop.

I ran into the problem of all the characters SayBackground texts displaying at the same time.

I searched the forum, saw a lot of references to a speech queue module, but wondered if I couldn't script it more simply.

So at the top:
Quote
// room script file
Overlay *ovredguard;  //overlay for the red guard
Overlay *ovblackguard; // overlay for the black guard
Overlay *ovgirlguard;  //overlay for the female guard
import bool guardstalking; //importing the varible to see if they are talking or interrupted
bool backstart = true;  // the variable to make the conversation loop

and down in the repeatedly execute section

Quote
function room_c() {
  // script for Room: Repeatedly execute
     if ((guardstalking == true) && (backstart == true)) { //not interupted and starting from the beginning
          ovredguard = cTguardr.SayBackground("Blah");  //Red speaks into his overlay
          backstart = false;  //restart varible is shut off
          SetTimer (1, 120); // timer for the first speech is set
}
   if ((IsTimerExpired(1)) && (guardstalking == true)) {  //after done speaking
     ovredguard.Remove(); //Red's overlay disappears
     ovblackguard = cTguardb.SayBackground ("Oh yeah?"); //Black Speaks
     SetTimer (2, 120); //timer for this speech is set
   }
   
   if ((IsTimerExpired(2)) && (guardstalking == true)){ // same as above
     ovblackguard.Remove();
     ovgirlguard = cTguardg.SayBackground ("Yeah.");
     SetTimer (3, 120);
   }
   if ((IsTimerExpired(3)) && (guardstalking == true)) {// the timer for the last speech is done
     ovgirlguard.Remove();// the last overlay is removed
     backstart = true; // the restart variable begins the loop again
   }
   if (guardstalking == false) {//and if anything interrupts it, the loop is broken
     cTguardb.FaceLocation(0,200,eBlock);// any reaction to the interruption
          cTguardg.FaceLocation(0,200,eBlock);
          cTguardr.FaceLocation(0,200,eBlock);
}
   
}



I'm happy with it because it's simple and can be restarted with a minimum of fuss.

The only downside is you can only have a maximum of 20 lines of repeating conversation because of the timer limits.

Any suggestions on tweaking this?
Title: Re: SayBackground -- Something clever?
Post by: SSH on Thu 08/11/2007 09:37:08
Yes, don't reinvent the wheel and use one of the Background Speech queue modules!
Title: Re: SayBackground -- Something clever?
Post by: quixotecoyote on Thu 08/11/2007 09:54:07
Why bother messing with a whole new module if a short script can do what you want instead?
Title: Re: SayBackground -- Something clever?
Post by: Rui 'Trovatore' Pires on Thu 08/11/2007 10:14:56
Use an array timer[100]. Instant 100 timers.
Title: Re: SayBackground -- Something clever?
Post by: quixotecoyote on Thu 08/11/2007 10:21:33
I haven't messed with arrays yet. 

Would you have to name your timer array like:

timer bkgtalk[100]

or does

timer[100] automatically increase the timers available.


The only odd artifact I'm finding with this is that it's screwed up where dialog appears for one of the guards.  Red and Girl are fine, but the Black guard's dialog appears in the center of the screen.  Not his SayBackground, just his dialog.



Title: Re: SayBackground -- Something clever?
Post by: Gilbert on Thu 08/11/2007 10:51:42
No, there's no pre-defined timer variable type.
Declare them like this:
int timer[100];

Unfortunately, as each array entry is just an ordinary integer variable you can't directly use them (with SetTimer(), IsTimerExpired(), etc.) like the pre-defined timers, you need to manually (with a while loop maybe) cycle through them and decrease the values of the active ones in repeatedly_execute_always().

When you need to "setup" a "timer" in the array, just assign a value to it, like:
timer[12]=400; //400 loops is 10 seconds normally

Then in repeatedly_execute_always():
int ii=0;
while (ii<100){
  if (timer[ii]>0) timer[ii]--;
  ii++;
}


To check whether a "timer" has "expired", just check whether its value is 0.

It's not very complicated, but not as simple as what a very short (depends on how you define "short") script can do, so you may opt to add these codes (not tested, may need ammendments) manually or try out a module.

@Redrum: You might want to help, but like in this case the solution is not that "instant" (at least this cannot be done directly without modifying the original codes), so your comment was more confusing than really helpful, as the solution is not clear (at least not for an average user). Please at least give more explanations.
 
Title: Re: SayBackground -- Something clever?
Post by: SSH on Thu 08/11/2007 13:59:49
Quote from: quixotecoyote on Thu 08/11/2007 09:54:07
Why bother messing with a whole new module if a short script can do what you want instead?

Because you just download and import the module and the add commands like this to your script:


qDisplaySpeech(cTguardr, "Blah");
qDisplaySpeech(cTguardg, "Oh yeah?");
qDisplaySpeech(cTguardr, "Yeah!");
Title: Re: SayBackground -- Something clever?
Post by: Rui 'Trovatore' Pires on Thu 08/11/2007 22:27:24
Gilbot, I know, but I've tried to think of many different examples. I actually wrote 4 or 5 posts, stuttering, writing and deleting.

Eventually I just thought "To heck with it - someone else can explain it better than I can, and maybe he'll just understand at once". Trust me, the examples I kept coming up with were even more confusing.
Title: Re: SayBackground -- Something clever?
Post by: quixotecoyote on Fri 09/11/2007 04:42:03
Well thanks to both of you.  If I need a longer conversation, now I know how to do it.
Title: Re: SayBackground -- Something clever?
Post by: Dualnames on Fri 09/11/2007 16:19:52
Use SSH modules. Sure can do some good shit.