MODULE: BgSpeech v2.2 - Now with non-blocking Wait command!

Started by Phemar, Mon 22/04/2013 17:16:18

Previous topic - Next topic

Phemar

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

An example of the code:

Code: ags
  BgSpeech.Add (cJoe, "Hi there!");
  BgSpeech.Add (cJoe, "How's the weather today?");
  BgSpeech.Pause (80);  //Adds a two second pause between these lines.
  BgSpeech.Add (cFarmer, "???", eBgSpeech_NotAnimating); //Farmer's talking animation won't play.
  BgSpeech.Add (cFarmer, "What did you say?");
  BgSpeech.Add (cBird, "SQUAWK!!!", 160, 40); // will display the speech at coordinates
  BgSpeech.Add (cJoe, "What was that!?");
  BgSpeech.Start (eBgSpeech_Loop); //optional param looping or not looping
                                   // 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: ags
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: ags
BgSpeech.Add (cEgo, "This is in the background!");


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

Code: ags
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: ags
BgSpeech.GetCurrentPlayingIndex ();


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

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

Code: ags
BgSpeech.GetCurrentText ();


Returns the text currently on the screen in the background.

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

Code: ags
BgSpeech.GetIndexLength ();

   
Gets the amount of messages currently queued up.

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

Code: ags
BgSpeech.GetQueueText (int index);


Returns the text at queue index 'index'.

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

Code: ags
BgSpeech.Looping ();


Returns true if the current conversation is looping.

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

Code: ags
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: ags
BgSpeech.Playing ();


Returns true of the speech is currently playing.

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

Code: ags
BgSpeech.Reset ();


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

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

Code: ags
BgSpeech.Resume ();


Resumes the speech from the last line it left off.

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

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

WrongTarget

Hello!

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

Phemar

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.

WrongTarget

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

Miori

Quote from: Phemar on Wed 01/05/2013 07:45:34
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

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: ags
function room_FirstLoad()
{
BgSpeech.Add(cChar1,"Test",eBgSpeech_NotAnimating);
BgSpeech.Pause(30);
BgSpeech.Start(eBgSpeech_Loop);
}


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?!

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: ags
static void BgSpeech::Start (BgSpeech_LoopStyle looping, int queueIndexToStartFrom) {
  
  if (t > p ) 
    t = 0;
  else
    t = queueIndexToStartFrom;
  
  oLoop = looping;
  
  if (!wait[t]) {
    if (at[t] == true)
      oSpeech = Overlay.CreateTextual (oX[t], oY[t], System.ViewportWidth - oX[t], 
                                       Game.SpeechFont, character[charID[t]].SpeechColor, oText[t]);
    else 
      oSpeech = character[charID[t]].SayBackground (oText[t]);
  
    if (anim[t]) {
      int l = character[charID[t]].Loop;
      character[charID[t]].LockView (character[charID[t]].SpeechView);
      if (l == 0)
        character[charID[t]].Animate (0, character[charID[t]].SpeechAnimationDelay, eRepeat, eNoBlock);
      else if (l == 1)
        character[charID[t]].Animate (1, character[charID[t]].SpeechAnimationDelay, eRepeat, eNoBlock);
      else if (l == 2)
        character[charID[t]].Animate (2, character[charID[t]].SpeechAnimationDelay, eRepeat, eNoBlock);
      else if (l == 3)
        character[charID[t]].Animate (3, character[charID[t]].SpeechAnimationDelay, eRepeat, eNoBlock);
    }
      
    float c = (IntToFloat(oText[t].Length) / IntToFloat(BGSPEECH_TEXT_READING_SPEED)) * IntToFloat(GetGameSpeed());
    int a = FloatToInt (c, eRoundUp);
    float displayTimeS = IntToFloat(BGSPEECH_MINIMUM_DISPLAY_TIME) / 1000.0;
    displayTimeS = displayTimeS * IntToFloat (GetGameSpeed());
    if (a < FloatToInt(displayTimeS, eRoundUp))
      a = FloatToInt(displayTimeS, eRoundUp);
    SetTimer (1, a);
  }


THIS IS THE ERROR LINE -

Code: ags
    if (at[t] == true)

Crimson Wizard

Quote from: Nixxon on Mon 16/11/2020 23:44:17
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

Also, just so that it's said:

Quote from: Nixxon on Mon 16/11/2020 23:44:17
THIS IS THE ERROR LINE -

Code: ags
    if (at[t] == true)


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

      oSpeech = Overlay.CreateTextual (oX[t], oY[t], System.ViewportWidth - oX[t], 
                                       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: ags
function region1_WalksOnto()
{
 cEgo.Walk(355,  142,  eBlock,  eAnywhere); //cEgo Walks onto platform
 cEgo.ChangeView(4); // cEgo invisible
 object[3].Visible = true; // Begin lock sequence
 object[3].SetView(16);
 object[3].Animate(3,  3,  eOnce,  eBlock);
 object[1].Visible = false; // turn off light glow
cBase.Say("Perfect, now get out and go over to that control panel");
oTruck.Visible = true; //Click Surveyor
OnPlatform = 1;
BgSpeech.Start(0);
BgSpeech.Add (cBase,  "Get out of the Surveyor");
BgSpeech.Pause (80);  //Two Second Pause
BgSpeech.Add (cBase,  "Stop dicking around");

}


I've tried pasting the BgSpeech code in a few other areas within the room script to no avail.

Snarky

Quote from: Nixxon on Tue 17/11/2020 03:39:01
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!


SMF spam blocked by CleanTalk