Not showing current tags/current choices or calling binded function(INK)

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
Qzynxx
Posts: 3
Joined: Wed Apr 26, 2023 6:19 am

Not showing current tags/current choices or calling binded function(INK)

Post by Qzynxx »

Hi all. I am using Ink in combination with the Unity Dialogue System, and I cannot seem to get any info on what is happening when the story is playing. I got the story playing correctly, but when I try to find out what the current tags and choices are, it's always 0, leaving me pretty stranded on expanding my project. This is my code:

Code: Select all

public class ChangeTextSpeed : MonoBehaviour
{
    [SerializeField] private TextAsset _inkJSON;
    public UnityUITypewriterEffect _typeWriterEffect;
    public DialogueSystemInkIntegration DSII;
    Story _story;


    public void Start()
    {
        _story = DSII.GetStory(_inkJSON.name);

        DSII.GetStory(_inkJSON.name).BindExternalFunction("SetIntVariable", (int value, int value1) =>
        {
            SetTypewriterSpeed(value);
        }
        );
    }

    public void Update()
    {
       // Debug.Log(DSII.GetStory(_inkJSON.name).currentChoices.Count);
    }


    public void SetTypewriterSpeed(float value)
    {
        _typeWriterEffect.charactersPerSecond = value;
    }
}
I know it's pretty simple. My dialogue does play out correctly when I enter the Box Collider, but I cannot get any info on what is happening inside the ink file. Using _story.currentChoices.Count doesn't work either...

It also doesn't call the bound function SetTypeWriterSpeed, does anyone know how this is happening? I feel like everything should work as there are no errors nor does my ink file go to the internal function SetIntVariable

Ink file:

Code: Select all

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

=== main ===
Do this test work? #speaker:luka
    * Yes#speaker:luka

        Yes it does!#speaker:Not luka so much
        ~ SomeText = "You chose yes"
        ->main
    *[No]#speaker:luka
        ~SetIntVariable(1, 0)
        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, also this text takes longer to scrool, click yes will make it go faster 
      
        ~ SomeText = "You chose no"
        ->main
    *Done
        When you choose this option you're just done!! But first theres a choice WITHIN a choice!
        **Ok I dont care
        **CHOICECEPTION
        -Now yer done
//        ->DONE
        
    *->
    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)==
stom programma
~return 1
User avatar
Tony Li
Posts: 21684
Joined: Thu Jul 18, 2013 1:27 pm

Re: Not showing current tags/current choices or calling binded function(INK)

Post by Tony Li »

Hi,

The DialogueSystemInkIntegration script already binds a function named SetIntVariable. Try this:

Create a subclass of DialogueSystemInkIntegration. Override the BindExternalFunctions method to also bind your function:

Code: Select all

public class MyDialogueSystemInkIntegration : DialogueSystemInkIntegration
{
    protected override void BindExternalFunctions(Story story)
    {
        base.BindExternalFunctions(story);
        story.BindExternalFunction("SetTypewriterSpeed", (float value) => { SetTypewriterSpeed(value); });
    }
}
Then use this subclass in place of the base DialogueSystemInkIntegration. See: How To: Replace Script with Subclass and Keep Field Assignments

In your story, include:

Code: Select all

EXTERNAL SetTypewriterSpeed(x)
and when you want to call the function in Ink, do something like:

Code: Select all

    *[No]#speaker:luka
        ~ SetTypewriterSpeed(50)
        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, also this text takes longer to scroll, click yes will make it go faster 
Post Reply