Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: WHAM on Sun 08/06/2025 11:35:24

Title: SELF-SOLVED: Detecting if say command has finished
Post by: WHAM on Sun 08/06/2025 11:35:24
Since I failed to find this in the manual and in the search: is there an easy way to detect if a character.say command has finished and the text dispalyed over the characters head has disappeared?
I am using the Lucasarts style speech and haven't found out any GUI element that the character.say text is bound to so I could check its text value or visibility, so I'm guessing its tucked away somewhere inaccessible.

What I'm trying to accomplish here is a simple subtitle system where a text label is assigned a bit of text whenever the say command triggers, which works fine, but trying to figure out when to clear the subtitle text (whether because the player skipped the dialogue or the timer ran out) so it doesn't linger on screen for longer than the standard speech text is what I'm failing to accomplish here. My initial idea was a simple repeatedly executed script that checks if any speech command is ongoing, and if not, clear the subtitle text away.


The minute I post the question I figure it out! The say command is blocking so I can just clear the label in the next line of code and not overthink things so much! IT WAS OBVIOUS!

Still, a bonus question: how does AGS calculate the time the .say command text stays up if no voice line is attached? I'm guessing its X milliseconds/frames per character, but didn't find this in the manual either. Just a vague "The text will remain on screen for a limited time".
Title: Re: SELF-SOLVED: Detecting if say command has finished
Post by: Khris on Sun 08/06/2025 11:51:55
The formula seems to be:

  int gameloops = ((StrLen(text) / game.text_speed) + 1) * GetGameSpeed();
https://www.adventuregamestudio.co.uk/wiki/AGS_tidbits_%26_snippets (about halfway down)

game.text_speed has a default value of 15. So 15 characters are displayed for two seconds, 30 characters for three seconds, etc.
Title: Re: SELF-SOLVED: Detecting if say command has finished
Post by: Snarky on Sun 08/06/2025 12:51:46
game.text_speed is now Game.TextReadingSpeed.

The total time is also affected by Game.MinimumTextDisplayTimeMs and by Speech.DisplayPostTimeMs.
Title: Re: SELF-SOLVED: Detecting if say command has finished
Post by: Crimson Wizard on Sun 08/06/2025 13:02:23
For the reference, if you ever need a continuous check instead:

For speech there's Speech.TextOverlay that returns speech overlay so long as it's displayed and null if there's none.
https://adventuregamestudio.github.io/ags-manual/Speech.html#speechtextoverlay
There's also Speech.PortraitOverlay in case of a sierra-style speech.

Testing for the speech voice may be done by checking if System.AudioChannels[0] has anything playing on it, as that's a reserved channel for the voice-over.

Since 3.6.2 there's a Speech.SpeakingCharacter property that returns a character whose blocking speech is currently being played:
https://adventuregamestudio.github.io/ags-manual/Speech.html#speechspeakingcharacter
This may be more convenient, because it does not depend on text/voice style.

Checking for blocking actions may be done using IsInterfaceEnabled, which returns false during blocking actions (or whenever you disabled interface yourself).
https://adventuregamestudio.github.io/ags-manual/Globalfunctions_General.html#isinterfaceenabled

Slightly more correct, but available only since the latest 3.6.2, is Game.InBlockingWait. It's better than the IsInterfaceEnabled, because interface may be disabled by a script command as well, and not 100% corresponds to a blocking action.
https://adventuregamestudio.github.io/ags-manual/Game.html#gameinblockingwait
Title: Re: SELF-SOLVED: Detecting if say command has finished
Post by: WHAM on Sun 08/06/2025 17:35:59
Thank you, folks! Immensely informative and useful!