Page 1 of 1

Ink Dialogue System Integration

Posted: Mon Feb 26, 2024 10:34 am
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?

Re: Ink Dialogue System Integration

Posted: Mon Feb 26, 2024 12:41 pm
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.

Re: Ink Dialogue System Integration

Posted: Tue Feb 27, 2024 12:53 am
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.

Re: Ink Dialogue System Integration

Posted: Tue Feb 27, 2024 1:14 am
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;

Re: Ink Dialogue System Integration

Posted: Tue Feb 27, 2024 9:12 am
by Tony Li
Hi,

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