Author Topic: MODULE: BgSpeech v2.2 - Now with non-blocking Wait command!  (Read 3430 times)

I've added a whole bunch of new functions, features and improvements.

An example of the code:

Code: Adventure Game Studio
  1.   BgSpeech.Add (cJoe, "Hi there!");
  2.   BgSpeech.Add (cJoe, "How's the weather today?");
  3.   BgSpeech.Pause (80);  //Adds a two second pause between these lines.
  4.   BgSpeech.Add (cFarmer, "???", eBgSpeech_NotAnimating); //Farmer's talking animation won't play.
  5.   BgSpeech.Add (cFarmer, "What did you say?");
  6.   BgSpeech.Add (cBird, "SQUAWK!!!", 160, 40); // will display the speech at coordinates
  7.   BgSpeech.Add (cJoe, "What was that!?");
  8.   BgSpeech.Start (eBgSpeech_Loop); //optional param looping or not looping
  9.                                    // and optional parameter which point of the queue to start in

Will queue up a bunch of speech to be looped in the background.

Download here.

Code: Adventure Game Studio
  1. BgSpeech.Add (Character *ID, String text, optional int x, optional int y, optional animating);

Will add 'text' to the queue, to displayed as speech for 'character'.

EG:
Code: Adventure Game Studio
  1. BgSpeech.Add (cEgo, "This is in the background!");

Will queue up "This is in the background!" to be displayed as speech for cEgo.

Code: Adventure Game Studio
  1. BgSpeech.Add (cEgo, "This is also in the background!", 120, 80, eBgSpeechNotAnimating);

Will add "This is also in the background!" to the queue to be displayed after the first message.
This time, it won't play the character's talking animation.

Optional x and y coordinates specify where the text should be displayed. Leave these
out for it to be displayed above the character's head.

Put these commands one after another to queue up speech.

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

Code: Adventure Game Studio
  1. BgSpeech.GetCurrentPlayingIndex ();

Gets the queue position of the currently displayed text. Returns an integer.

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

Code: Adventure Game Studio
  1. BgSpeech.GetCurrentText ();

Returns the text currently on the screen in the background.

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

Code: Adventure Game Studio
  1. BgSpeech.GetIndexLength ();
   
Gets the amount of messages currently queued up.

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

Code: Adventure Game Studio
  1. BgSpeech.GetQueueText (int index);

Returns the text at queue index 'index'.

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

Code: Adventure Game Studio
  1. BgSpeech.Looping ();

Returns true if the current conversation is looping.

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

Code: Adventure Game Studio
  1. BgSpeech.Pause (int loops);
 
Will add a pause between to lines of text for 'loops' amount of
game loops.
Basically a non-blocking form of Wait(int waitLoops);

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

Code: Adventure Game Studio
  1. BgSpeech.Playing ();

Returns true of the speech is currently playing.

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

Code: Adventure Game Studio
  1. BgSpeech.Reset ();

Resets the queue to its intial position, allowing you to overwrite it.

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

Code: Adventure Game Studio
  1. BgSpeech.Resume ();

Resumes the speech from the last line it left off.

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

Code: Adventure Game Studio
  1. BgSpeech.Start (optional looping, optional int QueueIndexToStartFrom);

This will start the speech going in the background.
Default is non-looping and from index 0 (the first message).

Pass eBgSpeech_Loop (or true) to loop the text or eBgSpeech_NoLoop (false or
leave it blank) to display the text only once.

QueueIndexToStartFrom is the position in the queue you wish to start playing from.

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

Code: Adventure Game Studio
  1. BgSpeech.Stop (optional ResetPlayQueue);

Will stop the backgound speech from playing.

Pass eBgSpeech_ResetPlayQueue to reset the queue or eBgSpeech_DontResetQueue
to leave the queue where it is.
Set to ResetPlayQueue by default.

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

KNOWN GLITCHES: Using BgSpeech.Add while the speech is playing causes the speech to jump to the next line. You can see why if you look at the code. I'm not sure how to fix this - If I don't stop the speech before adding to the queue the game seems to bug out.
« Last Edit: 24 Apr 2013, 09:33 by Phemar »

Hello!

Question! :)
Is this like SayBackground but with sound and animation enabled? What's the difference between this plugin and QueuedSpeech v3.5?
Thanks!

WrongTarget, that's exactly what it's like.

Although this version is out of date now, I've updated the entire thing and it is now no longer just a module for background speech, but rather an entire non-blocking script engine.

What this means is it is able to run ANY function in AGS completely non-blocking!

EDIT: I will release it in it's current form sometime, it's just heavily integrated into my current project at the moment so once I perfect this system I'll separate it and release it.
« Last Edit: 01 May 2013, 07:52 by Phemar »

Phemar,

That's outstanding. I'd very much appreciate that, and i'm sure a lot of other users in here too :) Thanks for the hard work.
In the mean time, this should do the trick :)

What this means is it is able to run ANY function in AGS completely non-blocking!

Absolutely awesome, always wanted something like this. Thank you very much :-D

Kumpel

  • On the way to break new ground...
    • I can help with AGS tutoring
    • I can help with animation
    • I can help with backgrounds
    • I can help with characters
    • I can help with proof reading
    • I can help with story design
    • I can help with translating
    • I can help with voice acting
After months of flawlessness I suddenly have a strange problem with this module which forces the player character to stop moving when BgSpeech is happening on screen.

Even a clean new project (Downloadable here) with only the demo room, the imported BgSpeech module and this added code:

Code: Adventure Game Studio
  1. function room_FirstLoad()
  2. {
  3. BgSpeech.Add(cChar1,"Test",eBgSpeech_NotAnimating);
  4. BgSpeech.Pause(30);
  5. BgSpeech.Start(eBgSpeech_Loop);
  6. }
  7.  

has the same problem for me, stopping the player's movements everytime the Test speech is shown on screen...

What do I miss? Isn't that module non blocking in every way? Why does it suddenly makes the player stop moving?

update:

while testing what causes this, I just noticed that the module now behaves like this:

After starting the module with BgSpeech.Start(...);
Using the indexed BgSpeech.Pause(...) causes the player character to stop moving when the pause starts.
Using BgSpeech.Add("...") only and non_looped causes the player character to stop moving only when the BgSpeech text disappears(?)
These codes block everything regarding the player character: Speech animation, walk animation, idle view. Even a blocking command like player.Walk(x,y,eBlock) is being stopped by it and is not continued when it's done with its hellish influence?!
« Last Edit: 18 Jan 2016, 17:47 by Kumpel »

Nixxon

  • -
I'm having some issues with this module.

Error when compiling after importing the script.

BgSpeech.asc(33): Error (line 33): '.ViewportWidth' is not a public member of 'System'. Are you sure you spelt it correctly (remember, capital letters are important)?

Code: Adventure Game Studio
  1. static void BgSpeech::Start (BgSpeech_LoopStyle looping, int queueIndexToStartFrom) {
  2.  
  3.   if (t > p )
  4.     t = 0;
  5.   else
  6.     t = queueIndexToStartFrom;
  7.  
  8.   oLoop = looping;
  9.  
  10.   if (!wait[t]) {
  11.     if (at[t] == true)
  12.       oSpeech = Overlay.CreateTextual (oX[t], oY[t], System.ViewportWidth - oX[t],
  13.                                        Game.SpeechFont, character[charID[t]].SpeechColor, oText[t]);
  14.     else
  15.       oSpeech = character[charID[t]].SayBackground (oText[t]);
  16.  
  17.     if (anim[t]) {
  18.       int l = character[charID[t]].Loop;
  19.       character[charID[t]].LockView (character[charID[t]].SpeechView);
  20.       if (l == 0)
  21.         character[charID[t]].Animate (0, character[charID[t]].SpeechAnimationDelay, eRepeat, eNoBlock);
  22.       else if (l == 1)
  23.         character[charID[t]].Animate (1, character[charID[t]].SpeechAnimationDelay, eRepeat, eNoBlock);
  24.       else if (l == 2)
  25.         character[charID[t]].Animate (2, character[charID[t]].SpeechAnimationDelay, eRepeat, eNoBlock);
  26.       else if (l == 3)
  27.         character[charID[t]].Animate (3, character[charID[t]].SpeechAnimationDelay, eRepeat, eNoBlock);
  28.     }
  29.      
  30.     float c = (IntToFloat(oText[t].Length) / IntToFloat(BGSPEECH_TEXT_READING_SPEED)) * IntToFloat(GetGameSpeed());
  31.     int a = FloatToInt (c, eRoundUp);
  32.     float displayTimeS = IntToFloat(BGSPEECH_MINIMUM_DISPLAY_TIME) / 1000.0;
  33.     displayTimeS = displayTimeS * IntToFloat (GetGameSpeed());
  34.     if (a < FloatToInt(displayTimeS, eRoundUp))
  35.       a = FloatToInt(displayTimeS, eRoundUp);
  36.     SetTimer (1, a);
  37.   }

THIS IS THE ERROR LINE -

Code: Adventure Game Studio
  1.     if (at[t] == true)
  2.  

BgSpeech.asc(33): Error (line 33): '.ViewportWidth' is not a public member of 'System'. Are you sure you spelt it correctly (remember, capital letters are important)?

This is because AGS 3.5.0 changed number of script functions and properties. Please refer to "Upgrading to AGS 3.5" topic in your manual.

You may either update script, or set "Script compatibility level" to something less than v3.5.0 (in General Settings).

Snarky

  • Global Moderator
  • Global Moderator
  • Mittens Lord
  • Private Insultant
    • Best Innovation Award Winner 2018, for his numerous additions to the AGS open source ecosystem including the new Awards Ceremony client and modules
    • Snarky worked on one or more games that won an AGS Award!
    •  
    • Snarky worked on one or more games that was nominated for an AGS Award!
Also, just so that it's said:

THIS IS THE ERROR LINE -

Code: Adventure Game Studio
  1.     if (at[t] == true)
  2.  

The AGS error reporting doesn't distinguish between a line with an if-statement and the following line, so in this case the error is actually on the line below.

Code: Adventure Game Studio
  1.       oSpeech = Overlay.CreateTextual (oX[t], oY[t], System.ViewportWidth - oX[t],
  2.                                        Game.SpeechFont, character[charID[t]].SpeechColor, oText[t]);

You see that this line actually uses the deprecated System.ViewportWidth that the compiler complains about.

Nixxon

  • -
Thanks Snarky!

I didn't even think to check the manual on this one, as it was module. Had no idea it would be so easy as to find / replace. That's neat!

I now appear to be getting this crash error however.



I must be implementing the code wrong, as I cannot see how it can loop the commands.

below is an excerpt from the room script.

Code: Adventure Game Studio
  1. function region1_WalksOnto()
  2. {
  3.  cEgo.Walk(355,  142,  eBlock,  eAnywhere); //cEgo Walks onto platform
  4.  cEgo.ChangeView(4); // cEgo invisible
  5.  object[3].Visible = true; // Begin lock sequence
  6.  object[3].SetView(16);
  7.  object[3].Animate(3,  3,  eOnce,  eBlock);
  8.  object[1].Visible = false; // turn off light glow
  9. cBase.Say("Perfect, now get out and go over to that control panel");
  10. oTruck.Visible = true; //Click Surveyor
  11. OnPlatform = 1;
  12. BgSpeech.Start(0);
  13. BgSpeech.Add (cBase,  "Get out of the Surveyor");
  14. BgSpeech.Pause (80);  //Two Second Pause
  15. BgSpeech.Add (cBase,  "Stop dicking around");
  16.  
  17. }

I've tried pasting the BgSpeech code in a few other areas within the room script to no avail.
« Last Edit: 17 Nov 2020, 03:44 by Nixxon »

Snarky

  • Global Moderator
  • Global Moderator
  • Mittens Lord
  • Private Insultant
    • Best Innovation Award Winner 2018, for his numerous additions to the AGS open source ecosystem including the new Awards Ceremony client and modules
    • Snarky worked on one or more games that won an AGS Award!
    •  
    • Snarky worked on one or more games that was nominated for an AGS Award!
I've tried pasting the BgSpeech code in a few other areas within the room script to no avail.

Do you mean the script where you call BgSpeech, or the actual script of the module?

As for the crash, notice that in Phemar's example he doesn't call BgSpeech.Start() until after he's finished adding the lines. (Compare trying to hit play before you add anything to your music playlist.) I'm guessing that's the problem.

Nixxon

  • -
Arrgh, damn it. How did I miss that....

It works beautifully!