Ink Dialogue System Integration

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
User avatar
ryanscottmurphy
Posts: 7
Joined: Mon Feb 26, 2024 10:22 am

Ink Dialogue System Integration

Post by ryanscottmurphy »

Hi there,
I'm using the Dialogue System Integration with Ink and I've noticed that the code initializes Lua variables that match and observe the global variables in Ink. I notice that if I start with my variables initialized on the Ink side that they don't appear to be read correctly until their first value change from my Ink script.

Code: Select all

void OnEnable()
{
    textField.text = DialogueLua.GetVariable(variableName).asString; // Receives the value "nil" until first change from Ink.
    DialogueManager.AddLuaObserver($"Variable['{variableName}']", LuaWatchFrequency.EveryUpdate, OnChanged);
}

Code: Select all

public void InitializeVariables() // Executed after Start Conversation in the DialogueSystemInkTrigger script.
{
    // Does not appear to trigger the observer, however this value is definitely available in the Ink script
    DialogueSystemInkIntegration.SetInkString(variableName, "Worm"); 
}
Any idea what I'm missing?
User avatar
Tony Li
Posts: 21678
Joined: Thu Jul 18, 2013 1:27 pm

Re: Ink Dialogue System Integration

Post by Tony Li »

Hi,

Try adding this line at line 307 of DialogueSystemIntegration.cs:

Code: Select all

DialogueLua.SetVariable(variableName, story.variablesState[variableName]);
I'll make the same change in the Ink integration for DS version 2.2.44.
User avatar
ryanscottmurphy
Posts: 7
Joined: Mon Feb 26, 2024 10:22 am

Re: Ink Dialogue System Integration

Post by ryanscottmurphy »

Thanks very much for the quick reply Tony!

I've inspected things a bit more from this code snippet. It looks like this change doesn't solve the problem for me, and from inspecting the Variable table in the Lua environment, it looks like this is a script execution order issue for me.

At Line 307 in the DialogueSystemIntegration.cs, each of the variables are already correctly initailized in the Lua environment Variable table (I don't know how yet, but they seem to be correct, so the code line that you've suggested appears to be redundant).

Does the Dialogue System have any event to announce that it's finished initialization? I suspect that if I initialize my UI values at the correct time, this will solve my problem.
User avatar
ryanscottmurphy
Posts: 7
Joined: Mon Feb 26, 2024 10:22 am

Re: Ink Dialogue System Integration

Post by ryanscottmurphy »

After rubber ducking myself in this forum I found what I was looking for.

Initializing my variables and Observers this way resolved my issues:

Code: Select all

if (DialogueManager.instance.isInitialized)
    AddVariableObservers();
else
    DialogueManager.instance.initializationComplete += AddVariableObservers;
User avatar
Tony Li
Posts: 21678
Joined: Thu Jul 18, 2013 1:27 pm

Re: Ink Dialogue System Integration

Post by Tony Li »

Hi,

Yup, that's exactly the way to do it!
Post Reply