Page 1 of 1

Changing Subtitle Chars Per Second from within ink file

Posted: Wed Apr 26, 2023 6:27 am
by Qzynxx
Hey guys, I'm trying to change the DialogueSystemControllers SubtitleCharsPerSecond, but I can't quite figure out how to do it, I'm new to both Ink and the Dialogue Systen, any help would be appreciated! Below is my Ink file

Code: Select all

VAR SomeText = ""
EXTERNAL SetIntVariable(x, y)
->main

=== main ===
Do this test work?
    * Yes
        Yes it does!
        ~ SomeText = "You chose yes"
        ->main
    *[No]
      ->SetIntVariable(CharactersPerSecond, 1)
        Well you say no, but actually yes, also the plus means that this option always stays present, removing the "+" and changing it to a "*" will make it continue to last option
      
        ~ SomeText = "You chose no"
        ->main
        
    *->
    Either way your choices don't matter, it does work. I'm calling a function now that prints out the option you chose. 
    ->chosen
    
=== chosen ===
    {SomeText}
    Now I will call a function that passes what you chose to the function
    ->chosenparam(SomeText)
    
===chosenparam(sometext)===
    {sometext} + 1
    ->DONE
-> END
==function SetIntVariable(x, y)==

~return 1

Re: Changing Subtitle Chars Per Second from within ink file

Posted: Wed Apr 26, 2023 8:02 am
by Tony Li
Hi,

What's the reason for changing the subtitle chars per second? There's probably an easier or cleaner way to accomplish your end goal. I suspect this has to do with sequences and timing, in which case you'll probably want to take a different approach.

Anyway, assuming you want to go ahead and change subtitle chars per second, let's tackle this in three steps.

First, you'll need to write a C# method to set DialogueManager.displaySettings.subtitleSettings.subtitleCharsPerSecond:

Code: Select all

public void SetSubtitleCharsPerSecond(float value)
{
    DialogueManager.displaySettings.subtitleSettings.subtitleCharsPerSecond = value;
}
Next, you'll need to declare SetSubtitleCharsPerSecond() as an external function in Ink. In Ink, add this line:

Code: Select all

EXTERNAL SetSubtitleCharsPerSecond(value)
In C#, similarly to how the integration binds its functions such as Sequence() and SetIntVariable(), bind your function:

Code: Select all

story.BindExternalFunction ("SetSubtitleCharsPerSecond", (float value) => 
{
    SetSubtitleCharsPerSecond(value);
});
Finally, use the function in Ink:

Code: Select all

~ SetSubtitleCharsPerSecond(50)

Re: Changing Subtitle Chars Per Second from within ink file

Posted: Wed Apr 26, 2023 10:56 am
by Qzynxx
I am so sorry I was still a bit confused, I meant the Unity UI Typewriter Effect's CharactersPerSecond.

I am trying to use tags in my ink file, but for some reason the storyalways says there are 0 tags.

It looks like this but It doesn't work. Sorry I didn't update my question appropriately!

Code: Select all

public class ChangeTextSpeed : MonoBehaviour
{
    [SerializeField] private TextAsset _inkJSON;
    public UnityUITypewriterEffect _typeWriterEffect;
    public DialogueSystemInkIntegration DSII;
    Story _story;
    public void OnTriggerEnter(Collider collider)
    {
        _story = DSII.GetStory(_inkJSON.name);
    }

    private void Update()
    {
        Debug.Log(DSII.GetStory(_inkJSON.name).canContinue);
        foreach (string tag in DSII.GetStory(_inkJSON.name).currentTags)
        {
            string[] splitTag = tag.Split(':');
            if (splitTag.Length != 2)
                Debug.LogError("Tag could not be appropriately parsed: " + tag);

            string tagKey = splitTag[0].Trim();
            string tagValue = splitTag[1].Trim();

            switch (tagKey)
            {
                case "speed":
                    _typeWriterEffect.SetSpeed(float.Parse(tagValue));
                    break;
            }
        }
    }

}

Re: Changing Subtitle Chars Per Second from within ink file

Posted: Wed Apr 26, 2023 12:41 pm
by Tony Li
Hi,

Why do you want to change the typewriter effect's Characters Per Second? If it's to fast forward or slow down parts of text, you can use RPG Maker-style control codes in your text; no need for any scripting.

If you want to use a different typewriter speed for each character, you can set up different subtitle panels with different subtitle text GameObjects that have typewriter effects that run at different speeds. Use a Dialogue Actor component on each character to specify which subtitle panel to use. Again, no need for any scripting. The subtitle panels can all be laid out to look exactly the same (apart from different typewriter speeds) if you want.

If neither of those are what you're looking for, you can write a C# method to change the typewriter speed, like in this post. Then register it as an external function in your Ink story (like my post above) and use it to change the typewriter speed.