Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: fiaschetta on Sun 12/11/2006 03:58:41

Title: Interact whit hotspost when other character talking
Post by: fiaschetta on Sun 12/11/2006 03:58:41
I have a room with two character (one is the player)...
If i interact with an hotspost, the character2 says: "You can't"..
But, i want that every 10 second, the  character2 begin to say (as a monologue) and while he says i can interact with hotspot.
Is possible?
Title: Re: Interact whit hotspost when other character talking
Post by: Khris on Sun 12/11/2006 06:25:18
Yes.
http://www.adventuregamestudio.co.uk/manual/Character.SayBackground.htm
Title: Re: Interact whit hotspost when other character talking
Post by: fiaschetta on Sun 12/11/2006 09:01:58
Ok.. But i want that the character talking every 10 second... and then, what is the script for interact only if the character2 talking?
Title: Re: Interact whit hotspost when other character talking
Post by: Ashen on Sun 12/11/2006 12:47:52
That's a little more complicated. Since the Character.Speaking property doesn't register SayBackground speech, you'll need some otherway. Easiest, I think, would be to use an Overlay pointer. Background Speech uses Overlays anyway:
Quote from: The Manual, SayBackground
This command works by creating a text overlay with an automatic removal time delay. The overlay is returned by this command, so you can save it for use later with Overlay.Valid and Overlay.Remove, if you want to remove the text prematurely.

So you can store the speech overlay in a pointer and check that.

// Top of room script (assuming this is just a one room thing)
Overlay *SayBG; // Overlay Pointer


// Later in script
SayBG = cNpc.SayBackground("You can't");


// Hotspot interaction
if ((SayBG != null) && (SayBG.Valid == true)) { // i.e. 'cNpc' is speaking
  // Whatever
}


As for the delay: read the Manual, a Timer should do it:

// Player enters room
SetTimer(1, 10*GetGameSpeed());


// Room repeatedly_execute
if (IsTimerExpired(1)) {
  SayBG = cNpc.SayBackground("You can't");
  SetTimer(1, 10*GetGameSpeed());
}
Title: Re: Interact whit hotspost when other character talking
Post by: fiaschetta on Tue 14/11/2006 04:48:03
I don't understand where i put Overlay* SayBg;

So... i put in "Player enter room (before)":
Overlay* SayBG;

in "Repeatledy excute":
if (IsTimerExpired(2)) {
  SayBG = cPg.SayBackground("You can't");
  SetTimer(2, 10*GetGameSpeed());
}


in "Player enter room (after)":
SetTimer(2, 10*GetGameSpeed());
SayBG == cPg.SayBackground ("You can't");


when i test game, the error is:
"parse error at 'SayBg' (in player enter room after)


Title: Re: Interact whit hotspost when other character talking
Post by: Gilbert on Tue 14/11/2006 05:12:55
Assignment of variables requires one equal sign only, so remove one '=' from the double '==' in your Player enters room script should work.

(double '==' is for variable comparisons, like if (a==b) ...)
Title: Re: Interact whit hotspost when other character talking
Post by: fiaschetta on Tue 14/11/2006 05:50:15
Ok... now the error is:

Variable "SayBg" is already defined


I understand where put  this:
// Top of room script (assuming this is just a one room thing)
Overlay *SayBG; // Overlay Pointer


// Later in script
SayBG = cNpc.SayBackground("You can't");

Title: Re: Interact whit hotspost when other character talking
Post by: Gilbert on Tue 14/11/2006 06:45:32
Since you had defined it on top of the script, you shouldn't define another variable of the same name in "Player enter room (before fade-in)", just remove/comment-out the Overlay* SayBG; line inÃ,  "Player enter room (before fade-in)" and keep the one on top of the script.
Title: Re: Interact whit hotspost when other character talking
Post by: fiaschetta on Tue 14/11/2006 08:03:58
Quote from: Gilbot V7000a on Tue 14/11/2006 06:45:32
Since you had defined it on top of the script, you shouldn't define another variable of the same name in "Player enter room (before fade-in)", just remove/comment-out the Overlay* SayBG; line inÃ,  "Player enter room (before fade-in)" and keep the one on top of the script.

Ok, Ok... but when character (saybg) speaks he doesn't animation speech... why?
Title: Re: Interact whit hotspost when other character talking
Post by: Gilbert on Tue 14/11/2006 08:37:15
From the manual entry for character SayBackground() function:
QuoteNote that the character's talking animation is not played if this function is used.

To get past this, the simplest way is to change SayBackground() to Say(), however, doing this will pause the game while the text is being displayed, which is probbly not you want (as you want the player to be able to interact while the character is speaking). In your case, you need to animate the character manually.

Here're some suggested procedures:
1. First, when the character starts to talk, start to animate.
2. Check repeatedly whether the character is still talking (i.e. if overlay is still valid), and stops the animation if not.

in "Player enter room (after)":
SetTimer(2, 10*GetGameSpeed());
SayBG = cPg.SayBackground ("You can't");
cPg.LockView(cPg.SpeechView);
cPg.Animate(cPg.Loop, 1, eRepeat, eNoBlock);

in "Repeatledy excute":
if (SayBG.Valid==0) cPg.UnlockView();
if (IsTimerExpired(2)) {
  SayBG = cPg.SayBackground("You can't");
  cPg.LockView(cPg.SpeechView);
  cPg.Animate(cPg.Loop, 1, eRepeat, eNoBlock);
  SetTimer(2, 10*GetGameSpeed());
}


I never tried it, so there're probably glitches here and there, but you may try it first to see if it works at all.
Title: Re: Interact whit hotspost when other character talking
Post by: fiaschetta on Tue 14/11/2006 15:30:00
Ok... works! Thanks!
Title: Re: Interact whit hotspost when other character talking
Post by: SSH on Tue 14/11/2006 16:15:03
My queued background speech module does the animation for you, as well as letting you queue up the speech, so have a look at:

http://ssh.me.uk/moddoc/QBGSpeechST.zip