Background Speech Function

Started by BernieLaraemie, Thu 21/07/2005 04:42:27

Previous topic - Next topic

BernieLaraemie

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
~~~~~
"It doesn't matter whether something is true, just that it is believed." -- Jim Morrison
~~~~~
THIS SPACE FOR RENT

Gilbert

You can check if the speech overlay is still valid.

Something like:
1. Declare:
Code: ags
Overlay* EGObgspeaking;


2. When he has to say something in background, save the returned overlay pointer:
Code: ags
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:
Code: ags

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

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

This is simpler I think.

strazer

(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:

Code: ags

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...

BernieLaraemie

Thank you, I shall begin implementing this and tell you how it goes :)

~~Bernie Laraemie
~~~~~
"It doesn't matter whether something is true, just that it is believed." -- Jim Morrison
~~~~~
THIS SPACE FOR RENT

BernieLaraemie

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
~~~~~
"It doesn't matter whether something is true, just that it is believed." -- Jim Morrison
~~~~~
THIS SPACE FOR RENT

kaputtnik

#5
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:

Code: ags

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:

Code: ags

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


And this here is on top of the room script:

Code: ags

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!
I, object.

Khris

You have declared two separate Overlay pointers.

It should look like this:

Code: ags
// global
Overlay* heraldspeaking;
export heraldspeaking;

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


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

kaputtnik

Alright, thanks! Works like a charm now - so much for copy&paste without being able to wrap your head around what the manual says...
I, object.

SMF spam blocked by CleanTalk