Adventure Game Studio | Forums

AGS Support => Modules, Plugins & Tools => Topic started by: Scorpiorus on Sat 21/02/2004 16:43:26

Title: DisplaySpeechBackground queued talking
Post by: Scorpiorus on Sat 21/02/2004 16:43:26
Having seen a couple of topics regarding background speech reminded me about an old script I had. I made some modifications so it could play talking animations - here it is:

Note: Only one speech queue can be run at a time, i.e. you can have only one conversation being run at background.

LAST UPDATE (23.05.04):
//
// Revision history:
//===================
// v1.02Ã,  [23.05.04]:
// - Added qSkipCurrentMessage() function to skip the message being currently displayed;
// - Play sound was added: qDisplaySpeech(EGO, "@3 hey"); will play "sound3.xxx" file;
//
//==============================================
// v1.01+ [06.04.04]:
// - Fixed import function Delay (should be import string Delay)
//
//==============================================
// v1.01Ã,  [25.02.04]:
// - Delay(int time) directive was added;
// - Fixed qIsTalking() returning 0 when the *last* phrase is being said;
// - Changed the repeatedly execute part of the script;
//


Script header:
import function qDisplaySpeech(int CharID, string message);
import function qStopSpeech();
import function qIsTalking();
import stringÃ,  Ã, Delay(int time);
import function qSkipCurrentMessage();



Main global script file (at the very top of it):
///////////////////////////////////////
// Background queued talking v1.02
///////////////////////////////////////


#define BUFFER_SIZE 300
#define AGS_STRING_LENGTH 200

struct MESSAGESTRING {
   intÃ,  CharID;
   intÃ,  anim_disabled;
   char byte[AGS_STRING_LENGTH];
};

MESSAGESTRING Buffer[BUFFER_SIZE];

function mod(int a, int b) { return a - (b*(a/b)); }

function BufferSetString(int sID, string text) {
   if (sID<0 || sID>=BUFFER_SIZE) { Display("error: SetString buffer error!"); QuitGame(0); }
   StrCopy(Buffer[sID].byte, text);
   return StrLen(text);
}

function BufferGetString(int sID, string buf) {
   if (sID<0 || sID>=BUFFER_SIZE) { Display("error: GetString buffer error!"); QuitGame(0); }
   StrCopy(buf, Buffer[sID].byte);
   return StrLen(buf);
}


int cur_str=0;
int cur_say=0;

int cur_overlay = -1;
int stop_talkÃ,  Ã, =Ã,  0;
int prev_charÃ,  Ã, = -1;
int cur_channel = -1;

function qDisplaySpeech(int CharID, string message) {
Ã, 
   int i = mod(cur_str, BUFFER_SIZE);

   BufferSetString(i, message);
   Buffer[ i ].CharID = CharID;
   cur_str++;
   //if (cur_str >= BUFFER_SIZE) cur_str = 0;
}

function qIsTalking() {
   return IsOverlayValid(cur_overlay);
}

function GetSoundNumber(string text) { //return 0 if unsuccessful

   int pos = StrContains(text, "@");
   if (pos<0) return 0;
   int i = pos + 1;
   string str_rez; StrCopy(str_rez, "");
   int Char = StrGetCharAt(text, i);
   while (Char>='0' && Char<='9' && i<StrLen(text)) {
      StrFormat(str_rez, "%s%c", str_rez, Char);
      i++;
      Char = StrGetCharAt(text, i);
   }

   while (i<=StrLen(text)) {
      StrSetCharAt(text, pos, StrGetCharAt(text, i));
      i++;
      pos++;
   }

   return StringToInt(str_rez);
}

function GetFreeChannel() { // returns a channel number
   ifÃ,  Ã,  Ã,  (IsChannelPlaying(5)==0) return 5;
   else if (IsChannelPlaying(4)==0) return 4;
   else return 3;
}

function qStopSpeechChannel() {
   if (cur_channel>2)
      if (IsChannelPlaying(cur_channel)) {
         StopChannel(cur_channel);
         cur_channel = -1;
      }
}

function qStopSpeech() {
   if (qIsTalking()) {
      qStopSpeechChannel();
      RemoveOverlay(cur_overlay);
      int i = mod(cur_say, BUFFER_SIZE);
      int CharID = Buffer[ i ].CharID;
      ReleaseCharacterView(CharID);
      if (prev_char > -1) { ReleaseCharacterView(prev_char); prev_char = -1; }
      stop_talk = 0;
      cur_say = cur_str;
   }
}

function DisplaySpeechQ_RE() {

   if (qIsTalking()==0) { // wait for character to finish talking
      if (cur_say < cur_str) { // if something left to be said

         int i = mod(cur_say, BUFFER_SIZE);
         int CharID = Buffer[ i ].CharID;

         string buf;
         BufferGetString(i, buf);

         qStopSpeechChannel();
         int cur_sound = GetSoundNumber(buf);
         cur_channelÃ,  Ã, = GetFreeChannel();
         if (cur_sound>0) PlaySoundEx(cur_sound, cur_channel);

         cur_overlay = DisplaySpeechBackground(CharID, buf);
         stop_talk = 1;

         if (prev_char > -1) ReleaseCharacterView(prev_char);
         prev_char = CharID;

         if (character[CharID].animating==0 && Buffer[ i ].anim_disabled==0) {
            int view = character[CharID].talkview+1;
            if (view < 1) { Display("error: Talk view isn't assigned!"); QuitGame(0); }
            int loop = character[CharID].loop;
            int delay = character[CharID].animspeed;
            SetCharacterView(CharID, view);
            AnimateCharacterEx (CharID, loop, delay, 1, 0, 0);
         }

         Buffer[ i ].anim_disabled = 0;
         cur_say++;
         //if (cur_say >= BUFFER_SIZE) cur_say = 0;
      } else if (stop_talk) { //finish talk animation
         if (prev_char > -1) { ReleaseCharacterView(prev_char); prev_char = -1; }
         qStopSpeechChannel();
         stop_talk = 0;
      }
   } // end of if (qIsTalking()==0)
}

string str_delay;
string Delay(int time) {

   int n=time;
   if (n<1) n=1; else if (n>=AGS_STRING_LENGTH) n=AGS_STRING_LENGTH-1;

   string format;
   StrFormat(format, "%%%dc", n);
   StrFormat(str_delay, format, ' ');
   Buffer[mod(cur_str, BUFFER_SIZE)].anim_disabled = 1;
   return str_delay;
}

function qSkipCurrentMessage() {
   if (qIsTalking()) RemoveOverlay(cur_overlay);
}



Main global script file (Repeatedly execute):

function repeatedly_execute() {
Ã, // put anything you want to happen every game cycle here
Ã, 
   DisplaySpeechQ_RE(); // place it before any other script code in rep. exec.
Ã, 
}



Main global script file (on_event function):
function on_event(int event, int data) {

   if (event == LEAVE_ROOM) qStopSpeech();

}




Functions:

----------------------------------------------------------
qDisplaySpeech(int CharID, string message)

Displays a CharID's character speech message at the background and plays an appropriate talk animation. You can queue up multiple messages by typing in several functions one after another.

Example:

qDisplaySpeech(EGO, "hi there MAN!");
qDisplaySpeech(MAN, "hey Roger");
qDisplaySpeech(EGO, "blah");
qDisplaySpeech(MAN, "blah blah");

Note: You can have a pause in the conversation by specifying a special Delay(int time) directive. The time parameter tells how long to wait before proceeding further. The valid range is 1 through 199. Where time=1 is the shortest delay.

qDisplaySpeech(EGO, "hi there MAN!");
qDisplaySpeech(MAN, "hey Roger");
qDisplaySpeech(EGO, Delay(50));
qDisplaySpeech(MAN, "blah blah");

Note: You can also have a sound to be played. Put the character '@' followed by a sound number, for example:

qDisplaySpeech(EGO, "@3 what is that?");

would display "what is that?" text message and play sound3.xxx file. Note, however, it plays a normal sound, not a voice speech from the speech.vox file!


----------------------------------------------------------
qStopSpeech()

Just stops background conversation.


----------------------------------------------------------
qIsTalking()

Returns 1 if conversation is going on. Otherwise returns 0.


----------------------------------------------------------
qSkipCurrentMessage()

Calling this function will skip currently displayed message and force the next one to proceed with.
This is useful if you want, for example, to let the player skip messages by pressing a certain key:

on_key_press:

if ((keycode!=0) && (keycode==game.skip_speech_specific_key)) qSkipCurrentMessage();

Skips the message if the game.skip_speech_specific_key variable is set and the player pressed that key.


~Cheers
Title: Re:DisplaySpeechBackground queued talking
Post by: Kweepa on Sat 21/02/2004 18:46:56
Fabulous!
I can see that coming in handy!
Title: Re:DisplaySpeechBackground queued talking
Post by: SimSaw on Mon 23/02/2004 14:50:48
Can I also use file speech with that script? Like:
qDisplaySpeech(EGO, "&11 Hand me your money!");
Title: Re:DisplaySpeechBackground queued talking
Post by: Scorpiorus on Wed 25/02/2004 15:48:39
QuoteFabulous!
I can see that coming in handy!
Glad you find it useful, Steve. :)

QuoteCan I also use file speech with that script? Like:
qDisplaySpeech(EGO, "&11 Hand me your money!");

I thought of it. But no it's not possible because the sound speech system is handled internally by AGS and there is no function currently to play a sound from the speech.vox file.

~Cheers
Title: Re:DisplaySpeechBackground queued talking
Post by: a-v-o on Wed 25/02/2004 22:21:55
To have also background speech sound the script can be modified to use PlaySound for this task.

something like: qDisplaySpeech (int charid, int sound, string message)

for no sound, sound is -1

Just an idea  ;D
Title: Re:DisplaySpeechBackground queued talking
Post by: Scorpiorus on Wed 25/02/2004 23:27:28
Thanks for the suggestion, a-v-o. But, yeah then it will play a sound*.wav file not one from the speech.vox and that I suspect SimSaw is asking of. I'd do it in a way how AGS does - i.e. qDisplaySpeech(EGO, "&5 blah blah") will play sound5.* (not ego5.wav)

~Cheers
Title: Re:DisplaySpeechBackground queued talking
Post by: Kinoko on Sat 20/03/2004 15:36:17
This works -great-, thanks! This really helps me out.

I only have two queries.

When I use the delay like in your example, I get an error message saying "Type mismatch; string with non-string".

Also, is there a way I can get my script of background speech to start again from the beginning when it finishes?
Title: Re:DisplaySpeechBackground queued talking
Post by: Scorpiorus on Tue 06/04/2004 11:10:16
Quote from: Kinoko on Sat 20/03/2004 15:36:17When I use the delay like in your example, I get an error message saying "Type mismatch; string with non-string".

Ah, I know what's wrong. I tested it from the main global script but you probably run a speech from a room script. But import declaration I made is wrong for Delay :) Thanks for spotting it. I've changed it now. To fix your problem open the script header and replace:
import function Delay(int time);
with
import string Delay(int time);

:)

QuoteAlso, is there a way I can get my script of background speech to start again from the beginning when it finishes?
Yeah, sure. Just make a use of qIsTalking() function by putting it within the repeatedly_execute:

function repeatedly_execute() {

    if (qIsTalking()==0) {
        qDisplaySpeech(EGO, "blah blah");
        qDisplaySpeech(EGO, Delay(20));
        qDisplaySpeech(EGO, "more blah");
        qDisplaySpeech(EGO, Delay(70));
    }

}


that will start talking once again after it was finished

[edit: qIsTalking corrected :)]

~Cheers
Title: Re:DisplaySpeechBackground queued talking
Post by: Kinoko on Sun 11/04/2004 17:02:43
ThankYOU Scorpiorus! ^_^ You just solved the major problem I had before releasing my game. Everything works beautifully now.

You might want to change that script there to "qIsTalking" too :)
Title: Re: DisplaySpeechBackground queued talking
Post by: Fekix on Sat 22/05/2004 16:27:01
thank you very much, very useful script!!

I think it's ok using this script in my game if i metion ur name in the credits?

And another question:
In the newest version of AGS it is possible to set "game.skip_speech_specific_key" command but this key won't work in ur script :( where do i have to set the proper command?
Title: Re: DisplaySpeechBackground queued talking
Post by: Scorpiorus on Sat 22/05/2004 16:38:41
Quote from: Fekix on Sat 22/05/2004 16:27:01I think it's ok using this script in my game if i metion your name in the credits?
Can you think of another reason what I posted it for? ;) ...Sure, and you don't necessarily have to mention me.

QuoteIn the newest version of AGS it is possible to set "game.skip_speech_specific_key" command but this key won't work in your script :( where do i have to set the proper command?
Well, the script is to play background speeching when you have a total control over the player character. How do you want the "skip_speech_specific_key" variable to affect the script?
Title: Re: DisplaySpeechBackground queued talking
Post by: Fekix on Sat 22/05/2004 17:02:25
my specific speech key is "." (keycode 46) like in Lucas Arts Games. I want that if i press "." the actual displayed speech removes and if there'sÃ,  next speech the next speech should be displayed.

I hope you understand what i mean.

In my room code:

qDisplaySpeech(JAN, "Now look at that. Blue sky and stuff");
Ã,  qDisplaySpeech(JAN, "Man, I'd give everything to be out of here and free, even the stuff I hide in my mattress.");
Ã,  FaceDirection(JAN, "down");
Ã,  qDisplaySpeech(JAN, "What? Didn't you know?");

and i want that if i press "." the next text will be displayed.

Edit: forgot to say that i use this script because i want that the player has nearly everytime total control over the PlayerCharacter, that's the reason why i use DisplaySpeechBackground instead of DisplaySpeech
Title: Re: DisplaySpeechBackground queued talking
Post by: Scorpiorus on Sun 23/05/2004 13:37:41
Thanks for clarifying - I've updated the script, see the qSkipCurrentMessage() example. :)
Title: Re: DisplaySpeechBackground queued talking
Post by: Fekix on Sun 23/05/2004 14:47:23
Thank you very much that is exactly what i need :)

Thank you again ;)
Title: Re: DisplaySpeechBackground queued talking
Post by: G on Thu 17/06/2004 19:32:05
This looks nice. But I have a problem while using it in my game.

I used the script to set a background conversation in a room, as soon as the player character enters in the room, the game crashes and gives me an error saying: 'AnimateCharacter: invalid loop number specified'

Why?

Thanks for the script anyway.

The Spanish AGSer: G
Title: Re: DisplaySpeechBackground queued talking
Post by: Scorpiorus on Thu 17/06/2004 20:56:49
That means the talking view of the character who is currently speaking doesn't have all the loops required. Remember that each talking view must have the exactly same number of loops as the normal (walking) view - i.e. each loop for each direction.
I'll add a check for the next version so it displays a more meaning error message.

ps. I'm glad the script came in handy btw :)
Title: Re: DisplaySpeechBackground queued talking
Post by: G on Fri 18/06/2004 23:21:33
Thanks Scorpiorus.

This script is a very nice work.
Title: Re: DisplaySpeechBackground queued talking
Post by: Lazarus on Tue 02/08/2005 09:18:41
I'm having a problem with background speech in that when I leave the screen and go into a new room the background speech seems to continue in the new room.

The only way I can stop it is by using "qStopSpeech()"
in the reatedly_execute in the new room which is not ideal.
The qStopSpeech(); doesn't seem to work properly I have placed the Leave room as below.

function on_event (int event, int data)
if (event == LEAVE_ROOM) qStopSpeech();

Any help would be grateful
Thanks
Title: Re: DisplaySpeechBackground queued talking
Post by: Scorpiorus on Mon 12/09/2005 16:51:45
I see two possible causes:

1.
You have to put the on_event(int event, int data) function into the main global script. That's where AGS expects it to be (not in the room script).
You can check if it's actually invoked by adding a Display(...) command, as follows:

function on_event (int event, int data) {
   if (event == LEAVE_ROOM)
   {
      Display("calling on_event for LEAVE_ROOM");
      qStopSpeech();
   }
}


2.
Another possibility is that your background conversation is run from withing the repeatedly_execute function. In that case there is a chance it's continuously restarted each game loop -- hence it can cause some sort of problem you're telling about. Make sure you run it only once (e.g. from within the players enters room interaction).

See if you can solve the problem now, but let me know if it still doesn't work.
Title: Re: DisplaySpeechBackground queued talking
Post by: Kweepa on Tue 13/09/2005 00:10:57
Hmm, that's kind of confusing.
Do they have the same functionality?
Title: Re: DisplaySpeechBackground queued talking
Post by: Scorpiorus on Tue 13/09/2005 01:15:48
I thought about converting this into a module but then somehow hesitated whether its functionality is enough to be a stand-alone script module. Think I just add multiple conversations feature (and possibly something else) and then make a module out of it.

:)
Title: Re: DisplaySpeechBackground queued talking
Post by: Lazarus on Mon 19/09/2005 10:02:51
Thanks for the reply
and looking at my last post I didn't explain it very well

I had copied exactly as you had written and was using the background talking in the room function :

function repeatedly_execute() {
Ã,  Ã,  if (qIsTalking()==0) {Ã,  Ã, 
Ã,  Ã,  Ã,  Ã, qDisplaySpeech(EGO, "blah blah");
Ã,  Ã,  Ã,  Ã, qDisplaySpeech(EGO, Delay(20));
Ã,  Ã,  Ã,  Ã, qDisplaySpeech(EGO, "more blah");
Ã,  Ã,  Ã,  Ã, qDisplaySpeech(EGO, Delay(70));Ã,  Ã, 
Ã,  Ã,  }
}

And when the player left the room the background talking was continuing in the next room, and it was here that I was placing the "qStopSpeech()" to counteract it.

At the moment I seemed to have fixed the problem.


Now I have acouple of questions the first is that when I have a NPC character talking in the background and I then remove him to replace the character with another different NPC there seems to be a delay before the first background talking stops, is there away to stop the background talking instantly?
At the moment I'm using

if (character[EGO].room == 34) {
Ã,  if (qIsTalking()==0) {Ã,  Ã, 
Ã,  Ã,  Ã,  Ã, qDisplaySpeech(EGO, "blah blah");
Ã,  Ã,  Ã,  Ã, qDisplaySpeech(EGO, Delay(20));
Ã,  Ã,  Ã,  Ã, qDisplaySpeech(EGO, "more blah");
Ã,  Ã,  Ã,  Ã, qDisplaySpeech(EGO, Delay(70));Ã,  Ã, 
Ã,  Ã,  }
}
else if (character[ROGER].room == 34) {
Ã,  Ã,  if (qIsTalking()==0) {
Ã,  Ã,  Ã,  Ã, qDisplaySpeech(EGO, "blah blah");
Ã,  Ã,  Ã,  Ã, qDisplaySpeech(EGO, Delay(20));
Ã,  Ã,  Ã,  Ã, qDisplaySpeech(EGO, "more blah");
Ã,  Ã,  Ã,  Ã, qDisplaySpeech(EGO, Delay(70));
Ã,  Ã, }
}

else { qStopSpeech();Ã,  }


The secound question is how did you workout the sizes for
#define BUFFER_SIZE 300
#define AGS_STRING_LENGTH 200
and what effect would there be increasing these values?

Thanks Lazarus


Title: Re: DisplaySpeechBackground queued talking
Post by: Scorpiorus on Tue 20/09/2005 00:52:23
Quote from: Lazarus on Mon 19/09/2005 10:02:51I had copied exactly as you had written and was using the background talking in the room function :

function repeatedly_execute() {
Ã,  Ã,  if (qIsTalking()==0) {Ã,  Ã, 
Ã,  Ã,  Ã,  Ã, qDisplaySpeech(EGO, "blah blah");
Ã,  Ã,  Ã,  Ã, qDisplaySpeech(EGO, Delay(20));
Ã,  Ã,  Ã,  Ã, qDisplaySpeech(EGO, "more blah");
Ã,  Ã,  Ã,  Ã, qDisplaySpeech(EGO, Delay(70));Ã,  Ã, 
Ã,  Ã,  }
}

And when the player left the room the background talking was continuing in the next room, and it was here that I was placing the "qStopSpeech()" to counteract it.

Ok, first let's sort out the qStopSpeech() problem because it's related to the other question. If I understand you correctly the above code is placed in the *room* repeatedly execute interaction event, right? I ask because you typed "function repeatedly_execute()" what usually is the name of global repeatedly execute which should be placed in the main global script file.
Also, I assume EGO is an NPC and not a player character.

The fact qStopSpeech() does its job when you put it within room's repeatedly execute means the function itself works properly. I guess there is a problem with on_event part, let's see...

Could you modify you main global script on_event function like this:

function on_event(int event, int data) {

   // ...
   // ...
   // some other code may be here
   // ...
   // ...


   // move the following lines at the very
   // end of on_event function:
   //
   if (event == LEAVE_ROOM) {
      Display("qIsTalking1 = %d", qIsTalking());
      qStopSpeech();
      Display("qIsTalking2 = %d", qIsTalking());
   }

}

Now, the background talking is started in the first room that causes the trouble (ie. backgroung talking does not stop when you leave it) and just before the player leaves the room you should see two displays:

qIsTalking1 = SOME NUMBER
qIsTalking2 = SOME NUMBER

So tell me please what there numbers are, for qIsTalking1 and qIsTalking2 respectively.
And let me know if it doesn't display anything at all.



Quotehow did you workout the sizes for
#define BUFFER_SIZE 300
#define AGS_STRING_LENGTH 200
and what effect would there be increasing these values?

AGS_STRING_LENGTH is the maximum length of an AGS string, you should not change it because it can cause serious problems with some versions of AGS, apart from that it won't change anything (for instance, if you increased the value it would just take more system memory and nothing else).

BUFFER_SIZE specifies the size of the buffer to store queued speech messages, it determines how many qDisplaySpeech calls you can have in one go, ie:

if (qIsTalking()==0) {Ã,  Ã, 
Ã,  qDisplaySpeech();
Ã,  qDisplaySpeech();
Ã,  qDisplaySpeech();
Ã,  qDisplaySpeech();Ã,  Ã, 
Ã,  ....
Ã,  ....
Ã,  etc but not more than BUFFER_SIZE in total
}

You can increase it which would take up more memory but I believe 300 is more than enough. ;)


p.s. So post those qIsTalking1, qIsTalking2 numbers so that we could resolve the original problem and I could then post a working example for the "changing characters" question.
Title: Re: DisplaySpeechBackground queued talking
Post by: Lazarus on Tue 20/09/2005 10:14:26
Yes you are right in both accounts I was showing where I had placed the "if (qIsTalking()==0) { " in the room script as I wanted the background talking to loop. And the background talking is between two NPC talking to each other and not the player.

I started in say room 1 where the two NPC characters are talking to each other and I got when leaving room 1:
qIsTalking1 =0
qIsTalking2 =0

now I'm in room 2 where the background talking has carried forward this however doesn't happen ever time but more times than not. When I leave room 2 to go back to room 1 I get
qIsTalking1 =1
qIsTalking2 =0
this doesn't happen every time as I also got
qIsTalking1 =0
qIsTalking2 =0
when leaving room 2.


I asked about buffers and string length as I'm playing around with the background talking to continue while the player interacts with objects etc.. because at the moment when a player interacts with something the background talking pauses. The problem I've got is the background talking doesn't follow on from each other in order eg..
1,2,3,4,5
it seems to display lines randomly eg.. 1,4,6,3
and increasing the buffer size almost sorts it out if thats any help

thanks
Title: Re: DisplaySpeechBackground queued talking
Post by: Scorpiorus on Tue 20/09/2005 13:39:14
Quote from: Lazarus on Tue 20/09/2005 10:14:26
I started in say room 1 where the two NPC characters are talking to each other and I got when leaving room 1:
qIsTalking1 =0
qIsTalking2 =0

That is what I have been suspecting! Here, qIsTalking1 returns incorrect value because with the background speech going on it should return 1. That's clear now why qStopSpeech doesn't remove background talking -- it checks qIsTalking internally and since it's 0 qStopSpeech doesn't even try disabling what's already off (as it thinks).

Quotenow I'm in room 2 where the background talking has carried forward this however doesn't happen ever time but more times than not. When I leave room 2 to go back to room 1 I get
qIsTalking1 =1
qIsTalking2 =0
this doesn't happen every time as I also got
qIsTalking1 =0
qIsTalking2 =0
when leaving room 2.

This makes it clear that sometimes qIsTalking works but some other times it doesn't.

QuoteI asked about buffers and string length as I'm playing around with the background talking to continue while the player interacts with objects etc.. because at the moment when a player interacts with something the background talking pauses. The problem I've got is the background talking doesn't follow on from each other in order eg..
1,2,3,4,5

Ah, did you put DisplaySpeechQ_RE(); inside the repeatedly_execute_always function by any chance? :)

You see, DisplaySpeechQ_RE(); is the main run-time routine that handles and updates background talking each game loop but it has to be placed within the main global repeatedly_execute function.
I see that you probably tried to make it work with blocking interactions but unfortunetely DisplaySpeechQ_RE() won't work correctly inside rep_ex_always because the last one is called at the end of a game script loop unlike normal repeatedly_execute that's invoked at the beginning instead.
Getting messages out of order is probably also caused by the very same issue -- if qIsTalking wrongly returns 0 from time to time qDisplaySpeech(...); is getting added to the buffer which eventually overflaws (ie more than 300 messages). Since it's a circular buffer it starts to overwrite the most outdated messages those you have at the beginning. I now see that I should have made it to report an error instead, because although the method I used should generally work fine, it also can go wrong if there is a logic mistake in the script such as putting qDisplaySpeech() in rep_exec without any sort of qIsTalking checks. Surely, qIsTalking in its turn must report the correct state then.

I'll see if I can make it work with repeatedly_execute_always but that would possibly require to change some of the framework code.


As for your first question concerning the characters change you can take a look at the demo game I just uploaded:

http://www.geocities.com/scorpiorus82/bgtalk_v10.zip requires AGS 2.7 (right click save as or copy&paste into the address bar)

See whether moving DisplaySpeechQ_RE() back to rep_exec solves the problem and if the code in the test game does what you are after.

Otherwise just let me know if something is wrong. ;)

ps. By the way what AGS version do you have, 2.7? I'm going to sort out that timing problem with DisplaySpeechQ_RE and also update it to use object-oriented scripting and script module support. Those two require AGS v2.7 or higher of course.
Title: Re: DisplaySpeechBackground queued talking
Post by: SSH on Tue 20/09/2005 14:59:34
Quote from: Scorpiorus on Tue 20/09/2005 13:39:14
ps. By the way what AGS version do you have, 2.7? I'm going to sort out that timing problem with DisplaySpeechQ_RE and also update it to use object-oriented scripting and script module support. Those two require AGS v2.7 or higher of course.

Since script modules can have their own repeatedly_execute, you don't need to bother fixing that timing thing: the user never need know about that _RE function at all!  ;D
Title: Re: DisplaySpeechBackground queued talking
Post by: Scorpiorus on Tue 20/09/2005 15:42:52
Hehe, it was going to be a simple one... but then Lazarus' having mentioned a possibility to have it going during blocking incited me to make it optionally work that way. I thus still need to re-code it a bit.

But yeah, module feature rocks -- "put that part here before this but after that" is no more!1 :)
Title: Re: DisplaySpeechBackground queued talking
Post by: Vel on Sat 24/09/2005 09:44:11
I have a questoin:
Will
qDisplaySpeech(EGO, "hi there MAN!");
qDisplaySpeech(MAN, "hey Roger");
qDisplaySpeech(EGO, Delay(50));
qDisplaySpeech(MAN, "blah blah");
SetGlobalInt(11,1);

Set the 11th global int to 1 after the player has seen the last message of the conversation or not?
Title: Re: DisplaySpeechBackground queued talking
Post by: Privateer Puddin' on Sat 24/09/2005 18:14:43
No, it wont do it at the end because the qDisplaySpeech aren't blocking (how it performed when i have done things after it)
Title: Re: DisplaySpeechBackground queued talking
Post by: Scorpiorus on Wed 28/09/2005 22:00:58
You can have:

at the top of the script:
bool bConversationStarted = false;

start talking:
qDisplaySpeech(EGO, "hi there MAN!");
qDisplaySpeech(MAN, "hey Roger");
qDisplaySpeech(EGO, Delay(50));
qDisplaySpeech(MAN, "blah blah");
bConversationStarted = true;

repeatedly execute:

if (bConversationStarted && qIsTalking()==0)
{
   SetGlobalInt(11,1);
   bConversationStarted = false;
}
Title: MODULE: DisplaySpeechBackground queued talking
Post by: SSH on Sun 27/11/2005 21:14:30
I have made a module for this. I tried to get hold of Scorp to check if it was OK to release, but he's not been around for a whuile, so I'll keep this low-key a release until I hear from him. Anyway, you can

download SSH's module here (http://www.lumpcity.co.uk/~ssh/QBGSpeechST.zip) (Requires AGS 2.71!)
Mirror (http://www.2dadventure.com/ags/QBGSpeechST.zip)

and it is nearly backwards compatible with the existing code. I changed the Delay directive to qDelay, so as not to clash with other module that might use such a common word. I also added qSetGlobalInt and qAddScore directives that work in the same way as Delay. Finally, I added the ability to use subtitles along with the speech, for whatever someone might want that for...
Title: Re: DisplaySpeechBackground queued talking
Post by: ManicMatt on Thu 01/12/2005 17:09:45
"Undefined token qdisplayspeech"

Nope, that can't be right! I put that big code in the top part of the global script like it asked, and put this following excerpt in the repeatingly executed room script file:

qDisplaySpeech(TRA, "hi there MAN!");
qDisplaySpeech(TRA, "hey Roger");
qDisplaySpeech(TRA, Delay(50));
qDisplaySpeech(TRA, "blah blah");

Not working... so I add above it:

qDisplaySpeech(int CharID, string message);

but don't know what to do with that...

(Should I be asking this in another thread?)
Title: Re: DisplaySpeechBackground queued talking
Post by: SSH on Thu 01/12/2005 17:19:31
Did you export the functions and import them in the script header?
Title: Re: DisplaySpeechBackground queued talking
Post by: ManicMatt on Thu 01/12/2005 17:24:02
I deleted the int charID bit after realising what it represents, and pasted the import definitions into the script header.

Now it says it doesn't know what this is:

return IsOverlayValid(cur_overlay);
Title: Re: DisplaySpeechBackground queued talking
Post by: SSH on Thu 01/12/2005 20:27:57
If you're using the original script with v2.7 or later, you'll need to make sure the  "Enforce object based scripting" setting on the General setting page of the editor is OFF
Title: Re: DisplaySpeechBackground queued talking
Post by: ManicMatt on Thu 01/12/2005 22:59:17
Ah! Yes, it['s not complaining, and the game runs...

however...

my character isn't saying anything!

I think I'm supposed to put this in my script, but the engine doesn't understand it.

DisplaySpeechQ_RE();

(Thanks for helping me out btw!)
Title: Re: DisplaySpeechBackground queued talking
Post by: monkey0506 on Fri 02/12/2005 02:43:43
I've also started modulificating this, but it's still pretty preliminary (no sounds or speech views yet).  But I can say that I got a module typed up that successfully ran a small conversation to in the background in a queued order (with some help from Scorporious's code ;D).  I'm trying to work out the animations, and then I'll work on the sounds.

Edit:

Script module released: http://www.adventuregamestudio.co.uk/yabb/index.php?topic=23806