Jibble

Author Topic: MODULE: BACKGROUND SPEECH (with animation&sound!) v1.1.0 (for AGS 3.2+)  (Read 8249 times)

While the more experienced scripters amongst you probably have this all figured out, I reckon the rest of you would have major difficulties getting a character to say something in the background, while animating a speech view and playing a voice clip.

If so, this module is just for you, then!

You'll never want to use the old Character.SayBackground again!  ;D

Module:  Background Speech
Version: 1.1.0 (updated by And-Or)

Download it here!
Mediafire link

Works with AGS 3.2!

What it does

- Plays background speech with text, sound & animation.
- Supports multiple characters

What it doesn't

Lip sync. No can do.

----------------------------

character.SayInBackground(String message, AudioClip* clip, int view, AudioPriority priority=eAudioPriorityNormal);
Similarly as in the previous version, prints the message in "talking style", plays clip and animates the view. The difference is that you can do it for several characters at the same time (as many, as many overlays and channels there are). Also, if you don't want to play the voice, you can pass null as clip. And if you don't want to change the animation, you can pass 0 as view.
The displayed text disappears after a time that depends on the game speed and the length of the text. You can also make the character stop speaking earlier, using StopSayInBackground.

character.StopSayInBackground();
Stops speaking in background (audio and animation).

character.BackgroundTalkActive();
This will tell you if the character is currently speaking in background.
« Last Edit: 13 Oct 2012, 15:00 by Electroshokker »

Makeout Patrol

  • Don't believe everything you hear on the radio.
    • I can help with AGS tutoring
    • I can help with backgrounds
    • I can help with proof reading
    • I can help with scripting
    • I can help with story design
    • I can help with web design
    • Makeout Patrol worked on a game that was nominated for an AGS Award!
I will be using this. Thanks for the great work!

Dualnames

  • Local Moderator
  • Pretty Badass
    • Dualnames worked on a game that won an AGS Award!
    •  
    • Dualnames worked on a game that was nominated for an AGS Award!
I'd say this would have been darm good, if it wasn't already done. Don't know if its improved though ;D. If you check SSH's and Scorpiorus background speech module it offers the same thing.
No more military army stuff. I'm alive and back.

monkey0506

  • SEND PIZZA.
    • Best Innovation Award Winner 2017, for his work to help AGS games reach the widest possible audience - through popular distribution platforms (Steam, Galaxy) as well as other operating systems (Android, Linux)
Actually SSH's (coughandminecough) background speech modules allow for queued background speech with animation. So it's actually a bit different. Don't know if it's forward-compatible with AGS, I don't know how he scripted it (coughminesnotcough).

abstauber

  • Cavefish
  • still mowing the lawn
    • abstauber worked on a game that won an AGS Award!
    •  
    • abstauber worked on a game that was nominated for an AGS Award!
I'm currently using SSHs and apparently your version :) - though I had to change 3 or 5 lines, but not a big deal.  The only real drawback is that it uses global INTs to trigger stuff out of a conversation.
And because it still works, I've been to lazy to implement a replacement.

But still thanks for sharing. If yours can trigger events out of a converstion, I might try.

Eggie

  • Golly!
    • Eggie worked on a game that was nominated for an AGS Award!
I....
could have so used this recently...
Balls.

Hi!

I'm using your script, but there is one problem. Sometimes the animation keeps on repeating without a break. So you see the chararcters speaking animation without speaking.

Sorry for bothering you again , but since I use your Character.SayInBackground-command, there are new bugs.
1) Sometimes the animation does not stop.
2) Far worse: there are moments in the game, in which you change the charakter. Sometimes, when you change the character, the new character can't move. I hoped to solve the problem by unlocking the view of the char before changing, but it doesnt seem to work.
 
I would be very happy for some advice
 
Cheers
Helme

As I'm working on the ags linux port atm, I unfortunately don't have the time to check this. I am aware that there are certain bugs in this module. I'll try to fix these at a later point in time, but if any of you feel the need to improve the module already, be my guest.

KrisMuc solved my problem.

If you add the following to the module-code, the bug is gone.

// in rep_ex

  if (player.ID == charid) {    // oder if (player == character[charid])
    speaking = false;
    character[charid].UnlockView();
    charid = -1;
  }
« Last Edit: 27 Jul 2009, 10:48 by Helme »

Updated to v1.0.1, new version works only for AGS 3.2 (uses new-style audio scripting)

If you want the old version for use in older AGS versions, you can get it here

Enjoy!

Hi,
Long-time reader, first time writer. I am just starting my adventure with AGS and wrote my first simple game to learn how to do it.
And one of the first obstacles I stopped at was this background talk problem (no audio, no animation). I found the Electroshokker's module, but I I could not use it since I needed more than one character to be speaking at the same time. So, I rewrote it to match my requirements. If anyone's interested, here it is:

http://www.megaupload.com/?d=54P764QV

Note that the above version was only tested with AGS 3.2.1.111

The functions are as follows:

character.SayInBackground(String message, AudioClip* clip, int view, AudioPriority priority=eAudioPriorityNormal);
Similarly as in the previous version, prints the message in "talking style", plays clip and animates the view. The difference is that you can do it for several characters at the same time (as many, as many overlays and channels there are). Also, if you don't want to play the voice, you can pass null as clip. And if you don't want to change the animation, you can pass 0 as view.
The displayed text disappears after a time that depends on the game speed and the length of the text. You can also make the character stop speaking earlier, using StopSayInBackground.

character.StopSayInBackground();
Stops speaking in background (audio and animation).
 

character.BackgroundTalkActive();
This will tell you if the character is currently speaking in background.


Hope someone will find this useful :)

And-or

And-or was kind enough to mail me his version (as MegaUpload is gone), and gave me permission to upload it and link to it here, in case anyone needs it:

http://www.mediafire.com/?sf3el98nssz734e

Note: He mentions, "although it might not be exactly the same version as I might have made some improvements".

Sorry to drag this topic up after such a long time but I'm finding a problem - the text display is off the right of the screen! Any ideas about that?

I have a problem importing this, it might be a noob thing (sorry if it is) but it seems when importing scripts in AGS it looks for a .scm file, it cant actually see the .ash or .acs files.

monkey0506

  • SEND PIZZA.
    • Best Innovation Award Winner 2017, for his work to help AGS games reach the widest possible audience - through popular distribution platforms (Steam, Galaxy) as well as other operating systems (Android, Linux)
That's because Electroshokker is a lazy jerk. :P

ASH and ASC files are just plain-text files. You can open them in Notepad. Then create a new script in your game, and copy the ASH file into your script's ASH, and the ASC file into your script's ASC. For your own convenience you could then right-click on that script and export it for easier importing into other projects.

Armageddon

  • Likes apples and nuts
Sorry to dig this up again but I'm having problems. It says.

Failed to save room room1.crm; details below
BackgroundSpeech.ash(38): Error (line 38): PE03: Parse error at 'AudioClip'

Because of this line.

import function SayInBackground(this Character*,  String message, AudioClip *clip, AudioPriority priority=eAudioPriorityNormal)

???

Dualnames

  • Local Moderator
  • Pretty Badass
    • Dualnames worked on a game that won an AGS Award!
    •  
    • Dualnames worked on a game that was nominated for an AGS Award!
Laters be late.

Regardless, I believe that occurs because the module demands that you set the setting on the General Settings regarding the use of the older or new sound system to new.
No more military army stuff. I'm alive and back.

Armageddon

  • Likes apples and nuts
Another problem.



:(

Armageddon

  • Likes apples and nuts
I could really use having this fixed for OROW, just noticed I forgot to post this too.


monkey0506

  • SEND PIZZA.
    • Best Innovation Award Winner 2017, for his work to help AGS games reach the widest possible audience - through popular distribution platforms (Steam, Galaxy) as well as other operating systems (Android, Linux)
Well if you follow your own code, you're passing null for the AudioClip:

Code: Adventure Game Studio
  1. cDriver.SayInBackground(..., null, ...);

And then in the module code, the first line is:

Code: Adventure Game Studio
  1. channel = clip.Play(priority);

Obviously if clip is null then you're not going to be able to call clip.Play. This is a problem due to poor coding of the module. You can correct this particular instance by changing the first line to this:

Code: Adventure Game Studio
  1. if (clip != null) channel = clip.Play(priority);
  2. else channel = null;

You're likely to encounter several other similar/related issues when dealing with code released by this particular author. And while modularizing it is all well and good, if you're not even doing a talkie game, I'll just point out that background speech with animation is effectively the same as:

Code: Adventure Game Studio
  1. // Script.ash
  2.  
  3. import Overlay* SayInBackground(this Character*, String text);
  4.  
  5. // Script.asc
  6.  
  7. Overlay *backgroundSpeech[]; // pointer to any character's background speech overlay
  8.  
  9. function game_start()
  10. {
  11.   backgroundSpeech = new Overlay[Game.CharacterCount]; // initialize array of pointers
  12. }
  13.  
  14. function repeatedly_execute()
  15. {
  16.   int i = 0;
  17.   while (i < Game.CharacterCount) // iterate all pointers checking for ended background speech
  18.   {
  19.     if ((backgroundSpeech[i] != null) && (!backgroundSpeech[i].Valid)) character[i].UnlockView(); // unlock character from speech view when done talking
  20.     i++;
  21.   }
  22. }
  23.  
  24. Overlay* SayInBackground(this Character*, String text)
  25. {
  26.   Overlay *o = this.SayBackground(text);
  27.   if ((o != null) && (this.SpeechView > 0))
  28.   {
  29.     this.LockView(this.SpeechView);
  30.     this.Animate(this.Loop, this.AnimationSpeed, eRepeat, eNoBlock, eForwards);
  31.   }
  32. }

That's literally all there is to it.
« Last Edit: 04 Jul 2013, 13:40 by monkey_05_06 »

Snarky

  • Global Moderator
  • Private Insultant
    • I can help with proof reading
    • I can help with translating
That's literally all there is to it.

If anyone's looking to implement this, that's not quite true. You have to actually store the overlay in the array (or the animation will never end), and null it out when you stop the animation (or the character will afterwards refuse to perform any other animations, including walking). This should do it:

Code: Adventure Game Studio
  1. // Script.ash
  2.  
  3. import Overlay* SayInBackground(this Character*, String text);
  4.  
  5. // Script.asc
  6.  
  7. Overlay *backgroundSpeech[]; // pointer to any character's background speech overlay
  8.  
  9. function game_start()
  10. {
  11.   backgroundSpeech = new Overlay[Game.CharacterCount]; // initialize array of pointers
  12. }
  13.  
  14. function repeatedly_execute()
  15. {
  16.   int i = 0;
  17.   while (i < Game.CharacterCount) // iterate all pointers checking for ended background speech
  18.   {
  19.     if ((backgroundSpeech[i] != null) && (!backgroundSpeech[i].Valid))
  20.     {
  21.       character[i].UnlockView(); // unlock character from speech view when done talking
  22.       backgroundSpeech[i] = null;
  23.     }
  24.     i++;
  25.   }
  26. }
  27.  
  28. Overlay* SayInBackground(this Character*, String text)
  29. {
  30.   Overlay *o = this.SayBackground(text);
  31.   if ((o != null) && (this.SpeechView > 0))
  32.   {
  33.     backgroundSpeech[this.ID] = o;
  34.     this.LockView(this.SpeechView);
  35.     this.Animate(this.Loop, this.AnimationSpeed, eRepeat, eNoBlock, eForwards);
  36.   }
  37. }