More than one NPC speaking at the same time? - SOLVED

Started by JudasFm, Thu 03/11/2011 21:23:00

Previous topic - Next topic

JudasFm

I was just wondering, can you run a DisplaySpeech command for two or more characters at once, so it looks like they're talking in unison?

The situation is this: at one point the player will wake up with screaming nightmares and go around each of their friend's houses in turn, looking for a place to sleep (long story; makes sense if you play the game).

Later they'll be talking to four of those friends and will say something like, "I've been having a little trouble sleeping lately," at which point all their friends will say in chorus, "WE KNOW!"

At least...they will if I can find out how to script it ???

I can get around it with objects and animations (put object that looks like all characters on top, make characters unclickable, animate object with speech, turn object off, make characters clickable again) but it seems a very complicated way of doing things.  I can't use just one object and no characters, since the player needs to speak to each character in turn.  

I'd be grateful for any help/thoughts on the subject.  I'm using AGS version 2.72

Khris

Even with 2.72, DisplaySpeech is obsolete, it should be Character.Say.
Regarding your question, you can use background speech:

Code: ags
  cNpc1.LockView(cNpc1.SpeechView);
  cNpc1.Animate(cNpc1.Loop, 4, eRepeat, eNoBlock);
  cNpc1.SayBackground("WE KNOW!");
  //... same for 2 & 3
  cNpc4.Say("WE KNOW!");            // normal speech so the game is paused for the duration
  cNpc1.UnlockView();
  // ... same for 2 & 3

monkey0506

I'm pretty sure that the old-style command was DisplaySpeechBackground, so the same thing applies to older versions of AGS too. It was more a matter of knowing how speech works than anything I think.

Speech in AGS is always blocking unless it's explicitly performed in the background. Background speech is always non-blocking. If you're not sure what I'm talking about, the manual explains what blocking scripts are. :P

Beyond that, Khris does make a fair point that if you're using AGS 2.72+ any new code should really utilize the OO functions (like Character.SayBackground). Some of the old-style commands don't even exist at all any more (hence the reason SSH made the BackwardsCompatible module).

JudasFm

Quote from: LeKhris on Thu 03/11/2011 22:08:00
Even with 2.72, DisplaySpeech is obsolete, it should be Character.Say.

I know; it's just that I learned in 2.6, I did a lot of programming and scripting in 2.6 (only upgraded because most of the templates from Maniac Mansion Mania are for 2.72) and so I still use a lot of 2.6 commands ;D Works great so far

QuoteRegarding your question, you can use background speech:

Code: ags
  cNpc1.LockView(cNpc1.SpeechView);
  cNpc1.Animate(cNpc1.Loop, 4, eRepeat, eNoBlock);
  cNpc1.SayBackground("WE KNOW!");
  //... same for 2 & 3
  cNpc4.Say("WE KNOW!");            // normal speech so the game is paused for the duration
  cNpc1.UnlockView();
  // ... same for 2 & 3


I tried that but it didn't quite work.  The characters animated fine, but the words only appeared above cNpc4's head (Say seems to negate any kind of background speech).

EDIT: Fixed it!  The script worked fine once I changed cNpc4 to speaking in the background though; I stuck in a Wait command at the end, set up a graphical variable and put a new Run Script command under it to continue the dialog.  Thanks for your help (and I learned something new about LockView too; I didn't know you could set it to a default Speech View.  Makes life much easier!)

Khris

Right, sorry, I even remember reading that Say cancels all BackgroundSpeech, somehow it didn't register when I typed that code.
Btw, if you don't want to put an arbitrary number in the Wait command, you can use:

Code: ags
  ...
  Overlay*o = cNpc4.SayBackground(...);
  while (o.Valid) {
    Wait(1);
  }
  ...


This will block the script until the timer for the speech runs out and it is removed.

SMF spam blocked by CleanTalk