Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: Hobbes on Tue 12/08/2003 15:34:14

Title: Using DisplaySpeechBackground properly
Post by: Hobbes on Tue 12/08/2003 15:34:14
ARGH!

My game is almost completed, and now I've run into a very annoying error. I'm doing something wrong, but I can't really figure out what.

My goal is this: To have my female NPC distract another NPC. This is done is a style very similar to "Fate of Atlantis" where Sophia distracts Charles Sternhard.

So, as soon as GlobalInt 11 hits the 3, this starts to take place.

So, this is the code in the room's Repeatedly Executed Event:

 if (GetGlobalInt(11)==3) {
 DisplaySpeechBackground(MARGE,"Blah blah blah....");  
 DisplaySpeechBackground(MARGE,"...yadda yadda yadda...");
 DisplaySpeechBackground(EDW,"Hahahaha! That was in my fourth year...");
 DisplaySpeechBackground(EDW,"Blah blah blah....");
 DisplaySpeechBackground(MARGE,"Blah blah blah! Haha!");
 DisplaySpeechBackground(MARGE,"Blah... Blah... Blah blah blah...");
 DisplaySpeechBackground(MARGE,"Yadda yadda yadda...");
 DisplaySpeechBackground(MARGE,"Blah...");

 }

Etc. It´s a total of 15 lines of BackgroundDialog.

So, when this happens, the game crashes and tells me I have too many overlays created. So I´m thinking the game is trying to spawn all these dialogs at the same time.

I´ve pondered putting in a Wait command, but that would mean that I loose control of my player character. So whatever code I add, should not interfere with the player character...

...Help?
Title: Re:Using DisplaySpeechBackground properly
Post by: SSH on Tue 12/08/2003 15:55:16
Hobbes,

you need to use IsOverlayValid on the return value of DisplaySpeechBackground to check if the lat line of dialog has disappeared yet and then move on to the next line of dialog: e.g.

if (GetGlobalInt(11)==3) {
if (GetGlobalInt(12)==0) {
SetGlobalInt(13, DisplaySpeechBackground(MARGE,"Blah blah blah...."));
SetGlobalInt(12, 1);
} elsif ((GetGlobalInt(12)==1) && (IsOverlayValid(GetGlobalInt(13))) {
SetGlobalInt(13, DisplaySpeechBackground(MARGE,"...yadda yadda yadda..."));
SetGlobalInt(12, 1);
} etc.

Lots of cutting and pasting for you m'lad!
Title: Re:Using DisplaySpeechBackground properly
Post by: Hobbes on Tue 12/08/2003 16:39:31
Hi SSH,

Thanks for the feedback!

Due to the awful ammount of copy-and-pasting, I've decided to have just "blah blah blah" and "yadda yadda yadda" in there...

So my code now looks like this:

if (GetGlobalInt(11)==3)
   {
     if ((GetGlobalInt(12)==0))
       {
       SetGlobalInt(13, DisplaySpeechBackground(MARGE,"Blah blah blah...."));
       SetGlobalInt(12, 1);
       }
   
   else if ((GetGlobalInt(12)==1) && (IsOverlayValid(GetGlobalInt(13))))
     {
     SetGlobalInt(13, DisplaySpeechBackground(EDW,"...yadda yadda yadda..."));
     SetGlobalInt(12, 0);
     }
 
}

Then only problem is, it's not working. The overlays keep going far too fast. Have I done something wrong?
Title: Re:Using DisplaySpeechBackground properly
Post by: Timosity on Tue 12/08/2003 16:45:30
should this be a global string not int:

SetGlobalInt(13, DisplaySpeechBackground(MARGE,"Blah blah blah...."));

I thought you could only set numbers in global ints
Title: Re:Using DisplaySpeechBackground properly
Post by: SSH on Tue 12/08/2003 17:18:17
Timosity: DisplaySpeechBackround returns an int, although the manual doesn't make this clear:

Quote
DisplaySpeechBackground (CHARID, string message)

This command works by creating a text overlay with an automatic removal time delay. The overlay ID is returned by this command, so you can save it for use later with IsOverlayValid and RemoveOverlay, if you want to remove the text prematurely.

However, the following manual entry indicates that overlay IDs are integers:

Quote
IsOverlayValid (int overlay_id)

Checks whether OVERLAY_ID is a current overlay or not. Returns 1 if it is, 0 if it isn't.

SUGGESTION: Maybe CJ can put the return values of functions in the manual too? I guess most are int or void.

Hobbes:

The manual doesn't say how the time the speech is displayed for is determined. ANyone know? CJ?


EDIT:

Oops! Hobbes: what you want is && (IsOverlayValid(GetGlobalInt(13))==0)

I got  the sense of that function the wrong way around!
Title: Re:Using DisplaySpeechBackground properly
Post by: MachineElf on Tue 12/08/2003 23:32:26
Damn... Thinking my ass off with this one. One way would be to use a timer, but then you'll have to know the exact time the speech stays on screen. Not too hard though.

But how about this:
First make a variable called "index" and one called "overlay". These should be put in the top of your room script. Then write the dialog in the global strings, 0-14 for 15 entries.
Then something like this in rep exec:

if (!IsOverlayValid(overlay))
{
int char;
if (index == 1 || index == 3...) // for all cases where MARGE is speaking
char = MARGE;
else char = CHARID; // editing, so can't see real id
overlay = DisplaySpeechBackground(char,GetGlobalString(index));
index++;
}

If you don't want to use the global strings, you could always do it a little less elegant:
if (!IsOverlayValid(overlay))
{
if (index == 0) overlay = DisplaySpeechBackground(...);
else if (index == 1) overlay = DisplaySpeechBackground(...);
else if (index == 2) overlay = DisplaySpeechBackground(...);
// and so on
}

This is the best way I can think of at the moment but I'm sure there are a lot of even better ways.

SSH: I think the return values are in the manual, but not just as clear as they could, as you mentioned. Functions not returning anything ought to be voids... Might be a few bools around. Not that it really matters though as ints are the only thing we can use anyway.

--- CORRECTED... ---
Title: Re:Using DisplaySpeechBackground properly
Post by: Hobbes on Tue 12/08/2003 23:57:44
Woohoo, thank you SSH!

Now, they're brilliantly talking about nothing at all whilst the player character can go on.

I've manually set their Speech-animations, so their lips are also moving in accordance with their speech.

Cool! :)
Title: Re:Using DisplaySpeechBackground properly
Post by: Hobbes on Tue 12/08/2003 23:58:45
Oops. Only now saw that Vargtass posted. If it's any help, here's the code which is now being used and works:

if (GetGlobalInt(11)==3)
   {
     if ((GetGlobalInt(12)==0) && (IsOverlayValid(GetGlobalInt(13))==0))
       {
       SetCharacterView(MARGE,6);
       SetCharacterView(EDW,12);
       SetGlobalInt(13, DisplaySpeechBackground(MARGE,"Blah blah blah...."));
       AnimateCharacter(MARGE,0,3,0);
       SetGlobalInt(12, 1);
       }
   
   else if ((GetGlobalInt(12)==1) && (IsOverlayValid(GetGlobalInt(13))==0))
     {
     SetGlobalInt(13, DisplaySpeechBackground(EDW,"...yadda yadda yadda..."));
     AnimateCharacter(EDW,3,4,0);
     SetGlobalInt(12, 0);
     }
 
}
Title: Re:Using DisplaySpeechBackground properly
Post by: MachineElf on Wed 13/08/2003 00:04:25
Yeah, that's basically the same thing. Good you sorted it out yourself!

(altough I of course think my way was prettier ;) )
Title: Re:Using DisplaySpeechBackground properly
Post by: TerranRich on Wed 13/08/2003 16:16:24
Quote from: SSH on Tue 12/08/2003 17:18:17
Timosity: DisplaySpeechBackround returns an int, although the manual doesn't make this clear:

Quote
DisplaySpeechBackground (CHARID, string message)

This command works by creating a text overlay with an automatic removal time delay. The overlay ID is returned by this command, so you can save it for use later with IsOverlayValid and RemoveOverlay, if you want to remove the text prematurely.

Looks quite clear to me. o_O