Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: Goldmund on Thu 30/09/2004 04:12:35

Title: sug.: auto-remove background speech
Post by: Goldmund on Thu 30/09/2004 04:12:35
Hello,

I sometimes use random events for characters talking in a room. I use DisplaySpeechBackground for this.
Now, it often happens that even when random's value is high, the speech is triggered while the previous one is still on screen. This makes for ugly and illegible clusters.

Would it be possible to make an existing background speech auto-disappear when the character says something new?
Title: Re: sug.: auto-remove background speech
Post by: Gilbert on Thu 30/09/2004 04:39:34
You can use IsOverlayValid() to check if the text is still on screen (thus you can remove it if a new line is said, or just don't display one more line of speech if the last one's still there). For example:
You can do something like:

int speechoverid;

...

ran=Random(10);
if (ran==5) {
Ã,  if (IsOverlayValid(speechoverid)Ã,  RemoveOverlay(speechoverid);
Ã,  speechoverid=DisplaySpeechBackground(EGO,"Blah!");
}


Title: Re: sug.: auto-remove background speech
Post by: TerranRich on Thu 30/09/2004 05:24:47
Yeah, but it doesn't work very well with normal speech, which is timed according to sentence length. So that "Blah" wouldn't stay on screen as long as "Hello, my name is Rich, and I'm a workaholic." Unless you use some algorithm where you set a timer for a time determined by the length of the string spoken. Something like one second per 3 words.
Title: Re: sug.: auto-remove background speech
Post by: Gilbert on Thu 30/09/2004 05:26:26
Terran, I can't get your point, did you read the thread?
Title: Re: sug.: auto-remove background speech
Post by: TerranRich on Thu 30/09/2004 05:32:03
Sorry, basically I was questioning putting up background speech before the last one "completes", so to speak. I was distracted while typing that post and it might have sounds like I was talkng about something else. :P
Title: Re: sug.: auto-remove background speech
Post by: Gilbert on Thu 30/09/2004 06:45:58
You don't need to time the speech yourself, as I mentioned:
Quote
or just don't display one more line of speech if the last one's still there
(though I only gave an example of terminating the last line immediately) if you don't want another line to be displayed before the last one was removed automatically, just do something like:

if (IsOverlayValid(speechoverid)==0)  {
   ran=Random(10);
   if (ran==5) speechoverid=DisplaySpeechBackground(EGO,"Blah!");
}
Title: Re: sug.: auto-remove background speech
Post by: strazer on Thu 30/09/2004 07:24:20
QuoteSomething like one second per 3 words.

The algorithm is
  time = ((StrLen(messagetext) / game.text_speed) + 1) * GetGameSpeed();

Edit:
That's in numbers of game loops.
Title: Re: sug.: auto-remove background speech
Post by: Goldmund on Fri 01/10/2004 01:53:58
Hm, yes, I thought of the workaround the way you suggested - thanks! - but I never really understood how the "OverlayIds" work, and I daresay that I'm not a bad scripter.
Still:
1) I don't really understand the way the code works. Where this "speechoverid" gets defined, and what command defines it??

2) Don't you think that such problems should be evaded by the engine itself? It seems only logical to me that when a character "background-speaks" his previous "background speech" should be erased off the screen... unless somebody really likes the cluster effects!

Title: Re: sug.: auto-remove background speech
Post by: Pumaman on Fri 01/10/2004 21:45:22
That seems a fair enough request, that DisplaySpeechBackground should check for existing background speech for that character, and remove it if found.