Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Gal Shemesh on Wed 21/06/2023 11:21:46

Title: Need assistance with setting a narrator screen message with voice
Post by: Gal Shemesh on Wed 21/06/2023 11:21:46
Hi everyone,

Sorry if this was asked before but I just can't find an exact thread about this issue.

I'm trying to make a Sierra "King's Quest 5/6" style game, where apart from regular character speech, there's an 'invisible' narrator that gives text information to the player upon looking / doing stuff, within a text box like the "Display" function. The thing I don't get is how to make this text box to show along with voice speech in the background, and that the speech will be based on the voice pack the game is set to run with.

I managed to import a voice sound to the engine and used its name with .play() and put it before the Display("string") line of code, but it's only for 1 language and it keeps playing even when the player interrupts and closes the text box. Besides, it's more complicated to work that way as I'll have to import all sound files to the engine. It also lacks the ability to pick sound files based on different languages. So I prefer to use speech as it pulls the sounds from the external Speech folder and its sub-folders for other langauges.

So I read a bit online and found that some are suggesting to use an invisible character as the narrator, and to position it in the center of the screen for presenting the text. So I tried it - after finding out that I can't use the 'cNarrator' script name for the character as it's already defined in the engine as a special character for dialogues, I gave my new narrator character the script name 'cNar'. I managed to achieve what I want, placing the narrator character in the middle of the screen and passing text and speech to it which works great in all languages. The only problem is that I don't want the text to be shown as speech text above its head but in a text box with a frame and all, that will also pause the game when shown, just like the "Display" function.

UPDATE:
I've just managed to write the code this way which is almost great, but the message displays only after the sound finish playing. The '&1' is the first sound file of the cNar character, pulled from either the 'Speech' folder for English or from the sub-folder 'Speech\Hebrew' for Hebrew:

function cEgo_Look()
{
  cNar.say("&1") & Display("Damn, you're looking good!");
 
}


Would appreciate some help.

Many thanks!
Title: Re: Need assistance with setting a narrator screen message with voice
Post by: Khris on Wed 21/06/2023 11:48:21
EDIT:
Disregard my post; Display() supports voice speech out of the box. By calling game.narrator_speech = -1;, the game will use voice files starting with NARR.

---

You probably need a custom function for this.

void Narrate(int cue, String text) {
  AudioChannel* ch = Game.PlayVoiceClip(cNar, cue);
  Display(text);
  if (ch != null) ch.Stop();
}

Add this to the Global header to be able to call the function from room scripts:
import void Narrate(int cue, String text);
Now call it like this: Narrate(1, "King Graham finally got rid of Cedric.");

Edit:
& is the bitwise and operator, it does not really do anything here.
Edit 2: NPE fix
Title: Re: Need assistance with setting a narrator screen message with voice
Post by: Gal Shemesh on Wed 21/06/2023 11:57:35
Thanks a million, @Khris! :) It works great when I have a voice file in the Speech folder and also in sub-folders for other languages.

The only problem I found is that if I use the calling syntax as a placeholder when I haven't recorded voices yet for all the text lines, then the 'ch.Stop();' makes the game crash. So I put it within an if statement that checks if 'ch' is NOT equal to 'null'. So now if I don't have a sound file in the Speech folder yet the game continues.

void Narrate(int cue, String text) {
  AudioChannel* ch = Game.PlayVoiceClip(cNar, cue);
  Display(text);
  if (ch != null) {
  ch.Stop();
  }
}
Title: Re: Need assistance with setting a narrator screen message with voice
Post by: Snarky on Wed 21/06/2023 13:32:08
I think this check is also necessary even if you do have a voice clip, in case the player doesn't click away the Display box until the clip has already finished playing.

Edit: No, I forgot that AudioChannels are persistent, and that if you get back a valid pointer, it will never turn into a null.
Title: Re: Need assistance with setting a narrator screen message with voice
Post by: Gal Shemesh on Wed 21/06/2023 13:35:50
Actually, since the text is shown like a 'Display()' fuction, the player can't do anything as long as the message is on the screen but to click in order to close the message and skip that bit. Which is fine for me.
Title: Re: Need assistance with setting a narrator screen message with voice
Post by: Gal Shemesh on Wed 21/06/2023 14:05:17
I will appreciate help on something similar to what you mentioned, @Snarky.

I've been tweaking the function with some 'if statements' so it will make sence with the 3 setting modes of 'Voice and Text / Text Only / Voice Only', as the modes did not affect the function and it always showed the text and played the sound no matter what setting was picked from the settings panel.

The new issue I'm facing now is when I set the game to 'Voice Only', as the speech sound plays without showing the text box on screen and the game keeps running in the background. Is there a way to make the function to sort of pause the game, the same as how the regular 'character.say()' function works which changes the mouse cursor to an hour-glass as long as the sound is playing, and that when it's done the control automatically returns to the player? The player should also have an option to skip the playing sound and get control back upon click.
Title: Re: Need assistance with setting a narrator screen message with voice
Post by: Snarky on Wed 21/06/2023 14:17:26
I don't think there is any way to freeze the game in exactly the same way that Display() does (which is a "harder" pause than the other blocks in AGS), but it should be possible to make it wait in the same way as speech does, by... actually playing it as a speech line in that case:

Code (ags) Select
  if(Speech.VoiceMode == eSpeechVoiceOnly && IsSpeechVoxAvailable())
    cNar.Say(String.Format("&%d",cue));
Title: Re: Need assistance with setting a narrator screen message with voice
Post by: Crimson Wizard on Wed 21/06/2023 14:28:51
I believe that Display (and all its functions family) can play voice precisely the same way as Say command does, if you call your voice files NARRXXXX.

Correction: Display uses a character index set by game.narrator_speech. It equals default player char on startup, but if this value is -1, then it will use NARRX files.

See here: https://adventuregamestudio.github.io/ags-manual/Gamevariables.html

Code (ags) Select
Display("&1 Bla bla bla");
will play voice file 1.

EDIT: the manual should be updated, this essential information needs to be added to "Display" article, and also to "Voice speech" article
Title: Re: Need assistance with setting a narrator screen message with voice
Post by: Gal Shemesh on Wed 21/06/2023 14:43:23
Quote from: Snarky on Wed 21/06/2023 14:17:26I don't think there is any way to freeze the game in exactly the same way that Display() does (which is a "harder" pause than the other blocks in AGS), but it should be possible to make it wait in the same way as speech does, by... actually playing it as a speech line in that case:

Code (ags) Select
  String cueString = String.Format("&%d",cue);
  if(Speech.VoiceMode == eSpeechVoiceOnly && IsSpeechVoxAvailable())
    cNar.Say(cueString);
Wow, that works just as expected! Thanks!!

Quote from: Crimson Wizard on Wed 21/06/2023 14:28:51I believe that Display can play voice precisely the same way as Say command does, if you call your voice files NARRXXXX.

Correction: you need to use DisplayAt for this, or DisplayAtY, as these functions act more similar to Say, being not as ultimately blocking as Display.
I will be glad to check this out - but does it work out-of-the-box or requires to have the custom Narrate function in the script header as well? And when writing the built-in Display() function, should I write it this way for calling the speech files: Display(&1 "some string.") ?
Title: Re: Need assistance with setting a narrator screen message with voice
Post by: Crimson Wizard on Wed 21/06/2023 14:44:34
@Gal Shemesh I corrected my reply once more after you replied, with example, please re-read it again.
Title: Re: Need assistance with setting a narrator screen message with voice
Post by: Gal Shemesh on Wed 21/06/2023 14:48:37
Quote from: Crimson Wizard on Wed 21/06/2023 14:44:34@Gal Shemesh I corrected my reply once more after you replied, with example, please re-read it again.
Yes, just saw it and was in the middle of modifying my previous reply. Thanks a lot! I also agree that this should be in the manual. I'm trying for hours to find heads and tails in the manual on these topics but it's currently lack of them, that's why I asked for help. Much appreciate all your help, from both of you! :)
Title: Re: Need assistance with setting a narrator screen message with voice
Post by: Gal Shemesh on Wed 21/06/2023 15:02:54
Quote from: Crimson Wizard on Wed 21/06/2023 14:28:51I believe that Display (and all its functions family) can play voice precisely the same way as Say command does, if you call your voice files NARRXXXX.

Correction: Display uses a character index set by game.narrator_speech. It equals default player char on startup, but if this value is -1, then it will use NARRX files.

See here: https://adventuregamestudio.github.io/ags-manual/Gamevariables.html

Code (ags) Select
Display("&1 Bla bla bla");
will play voice file 1.

EDIT: the manual should be updated, this essential information needs to be added to "Display" article, and also to "Voice speech" article
Can you please direct me to where / how to define the 'game.narrator_speech' variable to -1?
Title: Re: Need assistance with setting a narrator screen message with voice
Post by: Khris on Wed 21/06/2023 15:16:24
Just put
  game.narrator_speech = -1;
in game_start (or the first room's room_Load).

Regarding the syntax error in Display(&1 "Bla bla bla"): Display is a function that expects a string as first argument. You can't just put arbitrary characters in between the parens. The &1 belongs at the start of the string, exactly as with the Say command.
Title: Re: Need assistance with setting a narrator screen message with voice
Post by: Gal Shemesh on Wed 21/06/2023 15:32:37
Quote from: Khris on Wed 21/06/2023 15:16:24Just put
  game.narrator_speech = -1;
in game_start (or the first room's room_Load).

Regarding the syntax error in Display(&1 "Bla bla bla"): Display is a function that expects a string as first argument. You can't just put arbitrary characters in between the parens. The &1 belongs at the start of the string, exactly as with the Say command.
Thanks! It works great. Only difference compared to @Snarky script is that on 'Voice Only' mode the cursor remains as it was instead of changing to the hour-glass, and once the sound finished playing you actually have to make another click before the mouse cursor can return to interact with the environment; I just moved the mouse to the top edge to see if it can interact with the top bar icons in the Sierra style game and it doesn't pull the icons until I click on the mouse.
Title: Re: Need assistance with setting a narrator screen message with voice
Post by: Crimson Wizard on Wed 21/06/2023 15:38:51
Quote from: Gal Shemesh on Wed 21/06/2023 15:32:37on 'Voice Only' mode the cursor remains as it was instead of changing to the hour-glass, and once the sound finished playing you actually have to make another click before the mouse cursor can return to interact with the environment;

This sounds like a bug in the engine.
Title: Re: Need assistance with setting a narrator screen message with voice
Post by: Crimson Wizard on Wed 21/06/2023 17:27:14
Quote from: Crimson Wizard on Wed 21/06/2023 15:38:51
Quote from: Gal Shemesh on Wed 21/06/2023 15:32:37on 'Voice Only' mode the cursor remains as it was instead of changing to the hour-glass, and once the sound finished playing you actually have to make another click before the mouse cursor can return to interact with the environment;

This sounds like a bug in the engine.


Clarifying after some tests.

Cursor keeps its previous view during Display always, that's a normal behavior.

Display has to be removed with a player's input is a standard behavior, controlled by "game.skip_display" variable.

There's a problem with Display which plays a voice in a "Voice only mode". The issue is a lack of visual cues.
With speech you see a "wait" cursor, and optionally an animating character (SpeechView). With Display you won't see anything.

I guess this might be a reason to skip Display by a timer too when in "Voice only" mode. But this is not a high priority, as there are other workarounds, and alternatives to Display as well.
Title: Re: Need assistance with setting a narrator screen message with voice
Post by: Gal Shemesh on Wed 21/06/2023 18:43:17
Thanks @Crimson Wizard for all the testing. So you don't think that it's a bug after all in 'Voice Only' mode? I mean, it's weird that the pointer remains as if it's ready for hovering on hotspots and for revealing the top icon bar when it actually don't work until you click on the mouse - that is after the sound finished playing. All the other statements about the normal behaviors you mentioned are understandable.

Anyway with your, @Khris and @Snarky's kind help I managed to almost finish a basic upgraded template. I just have to work on the Hebrew font so it won't be a font of another game - currently it's Simon the Sorcerer's font in both English and Hebrew. Here's a short video describing what I've been working on: Upgraded Template Video (https://www.dropbox.com/s/7dk65q1jfri161c/Upgraded%20Tempalte%20with%20Multi%20Language%20%26%20Speech.m4v?dl=0)

A summary of what was changed:
1. The template is a multilanguage - based on English and has a Hebrew translation file.
2. Updated 256 characters font that contains both English and Hebrew character sets.
3. Ability to switch between Voice and Text for both English and Hebrew are in the in-game settings panel.
4. Speech folder contains all English voices and Speech\Hebrew contains all Hebrew voices.
5. Display() messages are set to be shown based on the 'Narrate(int cue, String text)' method for adding narration voices, which are based on an invisible cNarr character.
6. Fix for showing the wait / hour-glass cursor when on 'Voice Only' mode, using @Snarky assistance with the String cueString = String.Format("&%d",cue); line in Global Header.

Let me know what you think, and of course suggestions to make it better are very much welcome.
Also, kindly let me know where would be the suitable place to upload the complete template once I finish working on it, so users with multilanguage game in mind could use it as a starting point.

Thanks
Title: Re: Need assistance with setting a narrator screen message with voice
Post by: Gal Shemesh on Sun 09/07/2023 12:24:41
Hi guys,

I have another query on this topic regarding the IsSpeechVoxAvailable function.

I made this temporary hotkey for checking if I have any speech vox files in my game:

if (keycode == eKeyReturn)
{
  Display("IsSpeechVoxAvailable %d", IsSpeechVoxAvailable());
}

However, even if I'm running a game without any sound files in the Speech folder, the IsSpeechVoxAvailable returns the value 1 as if there are. What I'm trying to do is to make a condtion that checks if there are no speech files available when the game is launched, and if so then the Speech.VoiceMode will be changed to eSpeechTextOnly.

Same as if the players click on the Voice button in the Settings panel for changing the voice modes - if there is no speech files available I wish to show them a message saying that, and perhaps with some link that they need to access for downloading the speech packs from.

Thanks
Title: Re: Need assistance with setting a narrator screen message with voice
Post by: Crimson Wizard on Sun 09/07/2023 13:00:40
Quote from: Gal Shemesh on Sun 09/07/2023 12:24:41However, even if I'm running a game without any sound files in the Speech folder, the IsSpeechVoxAvailable returns the value 1 as if there are.

Is speech.vox present in Compiled folder?
Title: Re: Need assistance with setting a narrator screen message with voice
Post by: Gal Shemesh on Sun 09/07/2023 19:22:43
Nope. I have manually removed these files to be on the safe side from both the Data and Windows folders within the Compile directory. If I either run the game for a quick test from the editor or select to build all files where there is no speech files in the Speech folder, no VOX files get created, yet IsSpeechVoxAvailable remains to be equal to 1.

If I add a speech file and hit F5 for a quick test, the speech file plays in the game, though no VOX file gets created in the folders unless I selected to build all files - not sure if that's the correct behavior...
Title: Re: Need assistance with setting a narrator screen message with voice
Post by: Snarky on Sun 09/07/2023 20:24:06
Are you running the game with F5 through the editor, or running the exe directly?
Title: Re: Need assistance with setting a narrator screen message with voice
Post by: Gal Shemesh on Sun 09/07/2023 20:51:31
F5 hotkey from the editor.
Title: Re: Need assistance with setting a narrator screen message with voice
Post by: Crimson Wizard on Sun 09/07/2023 21:07:55
Please tell which version of AGS are you using?
Title: Re: Need assistance with setting a narrator screen message with voice
Post by: Gal Shemesh on Sun 09/07/2023 23:37:49
AGS Editor .NET (Build 3.6.0.50)
v3.6.0, July 2023
Title: Re: Need assistance with setting a narrator screen message with voice
Post by: Crimson Wizard on Mon 10/07/2023 02:53:26
I see now, when run from the editor, the AGS game reacts on mere presence of "Speech" folder, because it counts as an alternate clip location. When run from a compiled exe it will look for vox only.

Probably it could test for the presence of any sound files in the folder too.
Title: Re: Need assistance with setting a narrator screen message with voice
Post by: Gal Shemesh on Mon 10/07/2023 09:03:15
Yes, that would be great if it could behave that way.

I just checked whether the IsSpeechVoxAvailable() returns 0 when running the game from the EXE file and it actually does. Though I never thought there is a difference which is why I always relayed on running the game with F5 from within the editor.

Another thing I just noted in case the above thing gets fixed/added - if I compile all files once and a VOX file was created in the Compiled folder, when running the game from the editor it ignores the Speech folder completely and relays on the Speech.VOX file in the Compiled folder.

The same thing goes when adding more files to the Speech folder - if a Speech.VOX file was already compiled and I add new speech files to the Speech folder (or replace an existing file name with an alternate version) they don't play in the game until I re-compile all files. If I want the editor to relay on the actual Speech folder, I have to manually go into the Compiled\Windows folder and to delete the Speech.VOX file; I also manually delete the Speech.VOX file from the Compiled\Data folder to be on the safe side that it doesn't get use when testing the game.

I think that as long as the game is in development, testing the game from the editor should not relay and use the compiled VOX files, but rather relay on the presence of the source raw files in the game's folders.

Thanks for looking into this!
Title: Re: Need assistance with setting a narrator screen message with voice
Post by: Snarky on Mon 10/07/2023 10:11:07
Yeah, the way running games from the editor works (in terms of which files/folders it references) is complex and confusing. Glad you found the reason for your problem!
Title: Re: Need assistance with setting a narrator screen message with voice
Post by: Crimson Wizard on Mon 10/07/2023 11:38:21
Quote from: Gal Shemesh on Mon 10/07/2023 09:03:15I think that as long as the game is in development, testing the game from the editor should not relay and use the compiled VOX files, but rather relay on the presence of the source raw files in the game's folders.

This is how it is supposed to work, but if you say it does not, then it's a bug, and engine got broken somewhere during the development process.

The idea was that Speech folder has a priority over speech.vox, or rather plain files on disk should have a priority over the package. This lets to add new files without recompiling large vox.

Same is true for audio files, and AudioCache folder.

Quote from: Snarky on Mon 10/07/2023 10:11:07Yeah, the way running games from the editor works (in terms of which files/folders it references) is complex and confusing.

Engine registers lookup locations with category filter. There are 3 filters now, called arbitrary "random files", "audio files", "speech files".
Locations may be directories or packages.
When searching for a file, directories are supposed to have priority over a package.

When run from the editor, engine receives instructions for alternate locations via a command line.

Random files:
- Root project dir
- Compiled/Windows dir - looks for random game files (that is mostly in case user added custom files)
- game package (whether attached to exe or *.ags)

Audio files:
- AudioCache dir
- audio.vox

Speech files:
- Speech dir
- speech.vox
Title: Re: Need assistance with setting a narrator screen message with voice
Post by: Gal Shemesh on Mon 10/07/2023 13:00:21
Thanks guys for the input! Much appreciated.

I'm glad that at least I know by now how to troubleshoot this if this is a bug - I checked both scenarios when running my game from the EXE file, based on different conditions that I set when the speech VOX file exists and when it is not, so I'm not worried:

I set in the game_start() function a condition to check if the IsSpeechVoxAvailable is false. If so, it changes the default Voice & Text mode and button to Text Only. I also added an else if statement for displaying a text message to the players about the missing sound pack, if they were to click on the Voice button in the settings panel.

And so, if IsSpeechVoxAvailable is true, the game starts in the default Voice & Text mode and players could cycle through the different voice modes using the Voice button.

Now I'm back testing my game from the editor, and just make sure that there is no speech VOX file in the Compiled folder until if and when this is fixed, so when I add / change sound files in the Speech folder I don't have to recompile everything every time.

Again, thanks for looking into this! This is not taken for granted and I much appreciate you participation and help.  :)
Title: Re: Need assistance with setting a narrator screen message with voice
Post by: Crimson Wizard on Mon 10/07/2023 16:10:18
@Gal Shemesh

I tried this in 3.6.0, and it works as expected: if I add new files to Speech folder, or replace existing ones, without rebuilding speech.vox, then run the game from the Editor, then the files from the Speech folder are used.

Please tell in detail, how did you test this case in your game?
Title: Re: Need assistance with setting a narrator screen message with voice
Post by: Gal Shemesh on Mon 10/07/2023 17:20:17
Quote from: Crimson Wizard on Mon 10/07/2023 16:10:18@Gal Shemesh

I tried this in 3.6.0, and it works as expected: if I add new files to Speech folder, or replace existing ones, without rebuilding speech.vox, then run the game from the Editor, then the files from the Speech folder are used.

Please tell in detail, how did you test this case in your game?

Yes, that works for me too - the actual problem is this:

Rename your Speech folder to SpeechOld or something, and make a hotkey to see what isSpeedhVoxAvailable() returns to you - run the game from within the editor and it will return the value 1 instead of 0, even if there are no speech files available, which is incorrect. If you re-build all files and check this by running the game (that doesn't have any speech files in it) from the EXE, the hotkey will return to you the value 0, which is what it should have done by running the game from the editor. That's one problem.

The second problem is if you compile all files and then add or change an existing speech file in the Speech folder, when testing the game by hitting F5 from the editor, it won't reflect in the game unless you delete the Speech.VOX file from the Compiled folder.
Title: Re: Need assistance with setting a narrator screen message with voice
Post by: Crimson Wizard on Mon 10/07/2023 17:55:23
Quote from: Gal Shemesh on Mon 10/07/2023 17:20:17The second problem is if you compile all files and then add or change an existing speech file in the Speech folder, when testing the game by hitting F5 from the editor, it won't reflect in the game unless you delete the Speech.VOX file from the Compiled folder.

That's what I was referring to:

Quote from: Crimson Wizard on Mon 10/07/2023 16:10:18I tried this in 3.6.0, and it works as expected: if I add new files to Speech folder, or replace existing ones, without rebuilding speech.vox, then run the game from the Editor, then the files from the Speech folder are used.

1. Make a game with sounds in Speech folder (e.g. EGO1, EGO2, EGO3), and few dialog lines that use these.
2. Rebuild all files. Test that everything works.
3. Replace 1 voice file in Speech folder.
4. Press F5 to run a test (dont rebuild all files), the replacement works.
Title: Re: Need assistance with setting a narrator screen message with voice
Post by: Gal Shemesh on Mon 10/07/2023 20:01:34
Found the problem. It's quite confusing and hard to spot but I got it - it's not when adding new sound files, which work fine without recompiling. It is when you modify or replace the sound files that were already compiled, if for example you want to re-record a certain file or replace what is said in it while keeping the origianl file numbers.

Steps to reproduce:
1. Create a new game with the Sierra-style template.
2. Put 1 audio file such as Ego1.wav in the Speech folder.
3. Go to the cEgo_Look function and change the "Display()" with player.Say("&1 Damn, I'm looking good!");
4. Rebuild all files.
5. Run the game with F5 and confirm that the Ego1 file is played.
6. Close the game and delete the Ego1.wav from the Speech folder.
7. Copy an different audio file to the Speech folder and rename it to Ego1 as well.
8. Run the game with F5 - the new replaced file won't be heard but the previous one that was originally compiled.
Title: Re: Need assistance with setting a narrator screen message with voice
Post by: Crimson Wizard on Mon 10/07/2023 20:36:44
This is the precise situation I was referring to, and it worked for me.
I may test again, but it's quite strange.

Can anybody else try this out?

Does this sound replacement play at all, after you rebuild all files?
Title: Re: Need assistance with setting a narrator screen message with voice
Post by: Gal Shemesh on Mon 10/07/2023 21:03:37
Yep, if I rebuild all files then the new file that was replaced plays without any problem when running the game from the editor. Same as if I delete the Speech.vox file altogether from the Compiled folder.

Attached the new test game that I made if it helps - link (https://www.dropbox.com/scl/fi/et1ylk3kzydj7stl3x2tg/New-Game.zip?rlkey=1it778cfdmm9sf6xzjworzfjf&dl=0)

I've included in it a "_RESOURCES" folder with 3 speech files that I originally made for the Narrator in my version of the template. The first file is already in the Speech folder. I removed all the pre-compiled files so you could test it from scratch.

* There's also the Enter hotkey in it for the return value of the isSpeechVoxAvailable matter for your convenience. :)

If there's anything else you wish me to test from my side kindly let me know.
Title: Re: Need assistance with setting a narrator screen message with voice
Post by: Crimson Wizard on Mon 10/07/2023 21:21:32
I tried this project and it works as supposed to.

1. Rebuilt all files, look at character: it sais "Damn you're looking good".
2. Went to Speech dir and deleted Ego1.wav
3. Copied Ego3.wav into Speech dir, and renamed to Ego1.wav
4. Pressed F5 in the editor, look at character: it sais "Talking to yourself is a sign of madness".
Title: Re: Need assistance with setting a narrator screen message with voice
Post by: Gal Shemesh on Mon 10/07/2023 22:59:27
Thanks for the checking. I'm really not sure what's going on - I can swear it didn't work before in more than one project that I tested, but from unknown and awkward reason when I test the game now from the zip file that I shared, the replaced speech file is played correctly. I hope it will remain that way and that we didn't both encounter a temporary scenario that it actually works.

Thanks again for looking into this! So the only issue remains is the isSpeechVoxAvailable matter that keeps returning 1 when the game is begin test from the editor, even when there are no speech files in the Speech folder.
Title: Re: Need assistance with setting a narrator screen message with voice
Post by: Gal Shemesh on Tue 25/07/2023 12:56:39
Hi @Khris :)

On the same senario of the Narrate custom function you assisted me with, I'm trying to make the same thing for character.Say (any character) so the '&' with the speech file number will be outside of the actual string and not part of it, like when I call for the Narrate function as you instructed me:
Narrate(1, "Damn, you're looking good!");

However, I'm having some trouble modifiying the function to work.

The current function of yours with a little tuning for all the voice modes looks like this:

void Narrate(int cue, String text)
{
  String cueString = String.Format("&%d",cue);
  {
    if (Speech.VoiceMode == eSpeechVoiceAndText && IsSpeechVoxAvailable())
    {
      AudioChannel* ch = Game.PlayVoiceClip(cNarr, cue);
      Display(text);
      if (ch != null)
      {
        ch.Stop();
      }
    }
    else if (Speech.VoiceMode == eSpeechVoiceOnly && IsSpeechVoxAvailable())
    {
    cNarr.Say(cueString);
    }
    else if (Speech.VoiceMode == eSpeechTextOnly)
    {
      Display(text);
    }
  }
}

I've duplicated the custom function and managed to modify its code to make a specific character to say his cue, the same as the custom Narrate function does, but it's only for a specific character:

void Roger(int cue, String text)
{
  String cueString = String.Format("&%d", cue);
  {
    if (Speech.VoiceMode == eSpeechVoiceAndText && IsSpeechVoxAvailable())
    {
      AudioChannel* ch = Game.PlayVoiceClip(cEgo, cue);
      cEgo.Say(text);
      if (ch != null)
      {
        ch.Stop();
      }
    }
    else if (Speech.VoiceMode == eSpeechVoiceOnly && IsSpeechVoxAvailable())
    {
    cEgo.Say(cueString);
    }
    else if (Speech.VoiceMode == eSpeechTextOnly)
    {
      cEgo.Say(text);
    }
  }
}

Can you help me out making it work for any character?

Thanks

UPDATE:
I've just nailed it! The problem I had is that I declared the name 'character' after Character* which is already in used by AGS, so I changed it to 'myCharacter' instead.

Here's the code if anyone is interested not to include the speech file pointers ('&') in the actual character strings. This is very handy if you don't want to have the '&' pointer along with the strings in your translation file, and so you won't have to copy it for any translated lines below the original line. :)

// this function is used for showing character speech while having a speech file pointer OUTSIDE of the actual string.
// if you don't have a speech file yet just type 0 in its place.
// call for this function as follows where 1 is the first speech file of cCharacter:
// SayNew(cCharacter, 1, "A string for the character to say.");
void SayNew(Character* myCharacter, int cue, String text)
{
  String cueString = String.Format("&%d", cue);
  {
    if (Speech.VoiceMode == eSpeechVoiceAndText && IsSpeechVoxAvailable())
    {
      AudioChannel* ch = Game.PlayVoiceClip(myCharacter, cue);
      myCharacter.Say(text);
      if (ch != null)
      {
        ch.Stop();
      }
    }
    else if (Speech.VoiceMode == eSpeechVoiceOnly && IsSpeechVoxAvailable())
    {
      myCharacter.Say(cueString);
    }     
    else if (Speech.VoiceMode == eSpeechTextOnly)
    {
      myCharacter.Say(text);
    }
  }
}

Put the above in the GlobalScript header. And then call for it from other scripts like this, where cCharacter is your character ScriptName and 1 in the example is its first speech file Char1.ext in the Speech folder:

SayNew(cCharacter, 1, "the text string you wish the character to say");

* Note that this does not affect dialogue scripts and per my current knowledge, I'm not sure how to implement this in a way that dialogue scripts could use it with a speech file pointer that is outside of the literal string. So currently is you want to use this in dialogues you will need to use indentation and to use regular scripting method.
Title: Re: Need assistance with setting a narrator screen message with voice
Post by: Khris on Tue 25/07/2023 22:14:41
Nice work, just wanted to point out that AGS supports so-called extender functions.

void SayNew(this Character*, int cue, String text)
{
  String cueString = String.Format("&%d", cue);
  {
    if (Speech.VoiceMode == eSpeechVoiceAndText && IsSpeechVoxAvailable())
    {
      AudioChannel* ch = Game.PlayVoiceClip(myCharacter, cue);
      this.Say(text);
      if (ch != null)
      {
        ch.Stop();
      }
    }
    else if (Speech.VoiceMode == eSpeechVoiceOnly && IsSpeechVoxAvailable())
    {
      this.Say(cueString);
    }     
    else if (Speech.VoiceMode == eSpeechTextOnly)
    {
      this.Say(text);
    }
  }
}

Now you can use
cCharacter.SayNew(1, "the text string you wish the character to say");
Title: Re: Need assistance with setting a narrator screen message with voice
Post by: Gal Shemesh on Tue 25/07/2023 22:56:26
Quote from: Khris on Tue 25/07/2023 22:14:41Nice work, just wanted to point out that AGS supports so-called extender functions.

Thanks, @Khris! :) I'm learning from the best I guess.

And thanks for pointing this out! I didn't understand at first why I couldn't just use cCharacter along with my new custom function name and make it to work. So that extender you mention is the 'this' word before the Character*?

*By the way, I've just posted my final mini-game "Going Home", which wasn't possible without your, @Crimson Wizard and @Snarky's help. So thank you all! :) You may find it in the Completed Game Announcements section.
Title: Re: Need assistance with setting a narrator screen message with voice
Post by: Crimson Wizard on Tue 25/07/2023 23:18:36
Quote from: Gal Shemesh on Tue 25/07/2023 22:56:26And thanks for pointing this out! I didn't understand at first why I couldn't just use cCharacter along with my new custom function name and make it to work. So that extender you mention is the 'this' word before the Character*?

This is a respective manual entry:
https://adventuregamestudio.github.io/ags-manual/ExtenderFunctions.html

'this' in function argument defines which object type this function will belong to, while 'this' keyword in statements is a reference to "current object".

There's an article that overviews the object functions with 'this':
https://adventuregamestudio.github.io/ags-manual/OOProgramming.html
Title: Re: Need assistance with setting a narrator screen message with voice
Post by: Khris on Tue 25/07/2023 23:42:37
In the engine there's code similar to this:

class Character {
  int x, y;

  function Move(...) {
    ...
  }

  function Say(...) {
    ...
  }

  ...
}

An extender function allows you to "extend" this character class by your own functions, this way you can use them in your scripts like the built-in ones, using dot notation.

When you call player.SayNew(...), "this" refers to the player. When you call cNPC.SayNew(...), "this" refers to cNPC, and so on.