Adventure Game Studio | Forums

AGS Support => Advanced Technical Forum => Topic started by: Blackthorne on Fri 27/08/2021 17:21:36

Title: Custom Speech Command problem
Post by: Blackthorne on Fri 27/08/2021 17:21:36
In one of our games, we wrote a simple custom speech command for NPCs without dialogue portraits using the DisplayTopBar command.  It looks like this

Code (ags) Select
function TopBar60(this Character*, String WrittenText)
{
  Game.NormalFont = eFontSpeech;
  DisplayTopBar(60, this.SpeechColor, 16, this.Name, WrittenText);
  Game.NormalFont = eFontNormal;
}


Which works nicely, because you can just call the character name, and what they say easily

Code (ags) Select
cRoberto.TopBar60("I'm saying this here sentence.");

as opposed to always having to type

Code (ags) Select
DisplayTopBar(60, 15,16, "Roberto", "I'm saying this here sentence.");

It uses the color set in the character properties for the display window color, etc.  Nice.  Only problem is now I'm trying to add voices.... annnnddd, there's really no way to numbers these or use speechcenter.  I'm kind of stumped here. 

Any ideas?


Title: Re: Custom Speech Command problem
Post by: deadsuperhero on Tue 14/09/2021 12:59:32
Thought about this for a few minutes. I don't know if it's possible to invoke speech playback without an actual say command.

Here's a really hacky idea, though: could you pipe the WrittenText to a secondary Say command that's referenced off-screen? It's a really dirty idea, but it might work.

So like...



    function TopBar60(this Character*, Int LineNum, String WrittenText)
    {
      Game.NormalFont = eFontSpeech;
      DisplayTopBar(60, this.SpeechColor, 16, this.Name, WrittenText);
      this.SayAt(999, 999, 0, "&%n %s", LineNum, WrittenText);
      Game.NormalFont = eFontNormal;
    }



It's hacky and gross, and probably slightly incorrect (been a while since I hacked around with this stuff), but with some tweaking it might be possible to get something out of it?
Title: Re: Custom Speech Command problem
Post by: Crimson Wizard on Tue 14/09/2021 13:07:20
Quote from: DeadSuperHero on Tue 14/09/2021 12:59:32
It's hacky and gross, and probably slightly incorrect

It's actually how this is done most of the time (more or less).


I replied elsewhere, since 3.5.0 it's also possible to play voice directly:
https://www.adventuregamestudio.co.uk/forums/index.php?topic=59428.msg636639305#msg636639305

The function which splits text into voice number and an actual text: such function may be used as a replacement in Dialogs, as it's only parameter is String.
Code (ags) Select

function TopBar(this Character*, String WrittenText)
{
  int voice_num = 0;
  if (WrittenText.Chars[0] == '&')
  {
     int real_text_at = WrittenText.IndexOf(" ");
     voice_num = WrittenText.Substring(0, real_text_at).AsInt;
     WrittenText = WrittenText.Substring(real_text_at + 1, WrittenText.Length - real_text_at);
  }

  Game.NormalFont = eFontSpeech;
  AudioChannel *chan;
  if (voice_num > 0)
    chan = Game.PlayVoiceClip(this, voice_num);
  DisplayTopBar(40, this.SpeechColor, 16, this.Name, WrittenText); 
  Game.NormalFont = eFontNormal;
  if (chan != null)
    chan.Stop();
}