Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: BernieLaraemie on Thu 21/07/2005 04:42:27

Title: Background Speech Function
Post by: BernieLaraemie on Thu 21/07/2005 04:42:27
Is there a way to find out if a character is background speaking?

I have a script that plays out

cEgo.SayBackground("....");
cMan.SayBackground("....");

etc, and then at the end of it, one of them starts talking to the player with "cEgo.Say("...");"

But I can't find a way to get the conversation to play out BEFORE this happens.  ANy advice?  Like a cEgo.IsCharacterSpeaking = true idea?  or I am completely mixing myself up?

Thanks in advance for any help,

~~Bernie
Title: Re: Background Speech Function
Post by: Gilbert on Thu 21/07/2005 05:09:23
You can check if the speech overlay is still valid.

Something like:
1. Declare:
Overlay* EGObgspeaking;

2. When he has to say something in background, save the returned overlay pointer:
EGObgspeaking = cEgo.SayBackground("....");

3. If you want to check whether the text is still displayed, just check if the overlay is still valid via EGObgspeaking.Valid.

If I guessed what you need, you want  to make Ego and Man says something simultaneously, then, after that, Ego, says another line, you can do it like:

Overlay* EGObgspeaking=cEgo.SayBackground("....");
Overlay* MANbgspeaking=cMan.SayBackground("....");
while ((EGObgspeaking.Valid)&&(MANbgspeaking.Valid)) Wait(1);
cEgo.Say("...");


However, you can also first check whether EGO or MAN's line will last longer (usually the one with more characters), then use Say instead of SayBackground for that, for example:

cMan.SayBackground("Hello!");
cEgo.Say("How are you, man?");
cEgo.Say("Hehe.");

This is simpler I think.
Title: Re: Background Speech Function
Post by: strazer on Thu 21/07/2005 05:22:06
(I was typing while Gilbert replied, but I think my post clarifies point 3 a bit, so here it is:)

The Character.SayBackground function returns a pointer to the text overlay that is hovering over the character's head. You can check if this overlay is still valid to find out if the speech has timed out.

If I understand you correctly, you might want to try something like this:


Overlay *theoverlay; // define speech overlay pointer

function room_a() {
  // script for room: Player enters screen (after fadein)

  theoverlay = cMan.SayBackground("Blahblah."); // display speech in background and assign it to the speech overlay pointer

}

function room_b() {
  // script for room: repeatedly_execute

  if (theoverlay != null) { // if speech pointer has been assigned (if MAN is speaking)
    if (theoverlay.Valid == false) { // if speech has timed out

      cMan.Say("Yo, you there!");

      theoverlay = null; // reset speech overlay pointer
    }
  }

}


Haven't tested it...
Title: Re: Background Speech Function
Post by: BernieLaraemie on Thu 21/07/2005 17:13:17
Thank you, I shall begin implementing this and tell you how it goes :)

~~Bernie Laraemie
Title: Re: Background Speech Function
Post by: BernieLaraemie on Fri 22/07/2005 05:58:48
Hmm.  Everything I tried was just the same as ".Say", so, after hours of work, I just reverted to that.

Thanks for your help anyway, guys :)  I learned a lot about overlays :D

~~Bernie
Title: Re: Background Speech Function
Post by: kaputtnik on Tue 18/05/2010 11:08:13
Yep, old topic - but it is pretty much exactly what I need, only I can't really get it to work and need a little more help. I've got the overlay working correctly and nothing crashes, my script here simply does not do anything:


function LampWand_Interact()
{
 if (heraldspeaking != null){
   if (heraldspeaking.Valid == true){
   oLampWand.Visible=false;
   oStaff.Visible=true;
   cPu.AddInventory(iLampion);
}
   else if (heraldspeaking.Valid == false) {
   cPu.Say("Unauthorized borrowing suspicion matrix advises against this.");
   heraldspeaking=null;
}
}
}



That's what I've got in the global script:


Overlay* heraldspeaking;
function Doomsday(String message) {
heraldspeaking = cHerald.SayBackground(message);
}


And this here is on top of the room script:


import String message;
import function Doomsday(String);
Overlay* heraldspeaking;


What I would like it to do: Build a simple "distraction" puzzle where you can only snatch an item if the person is talking = distracted.

Thanks in advance!
Title: Re: Background Speech Function
Post by: Khris on Tue 18/05/2010 11:34:54
You have declared two separate Overlay pointers.

It should look like this:

// global
Overlay* heraldspeaking;
export heraldspeaking;

function Doomsday(String message) {
heraldspeaking = cHerald.SayBackground(message);
}


// room script
import function Doomsday(String message);
import Overlay* heraldspeaking;


Note that you only need to do this if you need the function and Overlay pointer in other rooms, too.
Title: Re: Background Speech Function
Post by: kaputtnik on Tue 18/05/2010 11:51:52
Alright, thanks! Works like a charm now - so much for copy&paste without being able to wrap your head around what the manual says...