Getting the Dialogue node from Lua functions

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
irve
Posts: 53
Joined: Fri Jan 15, 2016 9:35 am

Getting the Dialogue node from Lua functions

Post by irve »

Slightly confused.

Code: Select all

public static double Test(double value) {

	var state = DialogueManager.Instance.CurrentConversationState;
	var id = ArticyBridge.GetArticyIdField(state.subtitle.dialogueEntry);
	Debug.LogFormat("ModifyOnce: {0}", id);		

	return (double)value;
}
Let us ignore the Articy Id part as of now as I need it to mark the entry.

The function Test is put into the PC response instruction -- the dialogue written in Articy is like this:
NPC - hub - PC - PC
which probably converts into (?):
NPC - group - PC - PC

Now my Test function, when called from Lua gives the current entry as the NPC entry, while the actual clicked node from which it ran was the second PC line.

I am probably mistaken on the state.subtitle.dialogueEntry is the last NPC spoken line.
How could I find the actual entry from which I am calling the Lua function? The function should be able to run on both PC and NPC entries...
User avatar
Tony Li
Posts: 22108
Joined: Thu Jul 18, 2013 1:27 pm

Re: Getting the Dialogue node from Lua functions

Post by Tony Li »

Is the Test function on a separate Instruction node or on the PC response node itself?

I'll test this when I get back into the office and let you know what I find.

You might gain some insight by examining the conversation in the Dialogue Editor window. It will show you how the dialogue was converted. If you keep the Dialogue Editor window open on the conversation during play, it will show you which node is active, which might also be helpful.
irve
Posts: 53
Joined: Fri Jan 15, 2016 9:35 am

Re: Getting the Dialogue node from Lua functions

Post by irve »

Now I get it, dialogue window made it obvious.

I made a circular dialogue and the Test shows me the node into which I have just "gone". So the actual sequence was basically:
NPC - hub - PC - PC - (same) NPC

My intuition was that the conversation state changes after the "instruction" has been processed, but it seems that the conversation gets into the next state at the same time. Also changing the behaviour might break things that rely on the current behaviour.

I suppose that I can catch the dialogue entry from the currently displayed line and from the button click handler on the interface.

Sorry about the confusion, thank you for your time.
User avatar
Tony Li
Posts: 22108
Joined: Thu Jul 18, 2013 1:27 pm

Re: Getting the Dialogue node from Lua functions

Post by Tony Li »

I'm glad you got to the bottom of it. Sorry for the confusion it caused. Some amount of peculiarities like this are unavoidable to handle all the cases that the Dialogue System supports.

Another one that often throws people is that the Dialogue System evaluates conditions one level ahead of what most users expect. This is because it needs to know what options are available in the next level to handle certain continue button modes. (This post provides more info on that.)
irve
Posts: 53
Joined: Fri Jan 15, 2016 9:35 am

Re: Getting the Dialogue node from Lua functions

Post by irve »

This dual lookup was discovered and for conditions I intend to enforce a strict "no side-effects" rule.

For player responses I can set the current node for Lua on the click event.
For NPC spoken dialogue it seems that OnConversationLine runs after the Lua script. Is there any point between selection of the new node (which I cannot predict reliably) and running of the script, into which I could hook?

Or is there a possibility of using the built-in evaluation fromt the OnConversationLine event somehow?
User avatar
Tony Li
Posts: 22108
Joined: Thu Jul 18, 2013 1:27 pm

Re: Getting the Dialogue node from Lua functions

Post by Tony Li »

irve wrote:For NPC spoken dialogue it seems that OnConversationLine runs after the Lua script. Is there any point between selection of the new node (which I cannot predict reliably) and running of the script, into which I could hook?
Yes, another event OnPrepareConversationLine(DialogueEntry) is called before evaluating the node's links and running its Script. Its parameter is a DialogueEntry, not a Subtitle.

The order is:
  • Select dialogue entry node X.
  • OnPrepareConversationLine(X).
  • Execute node X's Script.
  • Invoke node X's OnExecute() event. (Dialogue System 1.6.6.1+)
  • Evaluate the Conditions of nodes that X links to. (Store in a Subtitle record.)
  • OnConversationLine(Subtitle).
  • Play node X's Sequence.

I don't know if this will be helpful, but the DialogueManager also has an IsDialogueEntryValid delegate method. If you assign a function to this method, the Dialogue System will call it when evaluating Conditions. The function must return true, in addition to the Conditions evaluating true, for the Dialogue System to use that node.
irve
Posts: 53
Joined: Fri Jan 15, 2016 9:35 am

Re: Getting the Dialogue node from Lua functions

Post by irve »

Thanks, this was exactly the function we needed. In case anyone wants to have something similar I here's the relevant code.

Now we have a component with Dialogue Manager:

Code: Select all

static DialogueEntry LastEntry;

// note: this runs also on barks
public void OnPrepareConversationLine(DialogueEntry entry) {
	LastEntry = entry;
}
And another in Lua function registration:

Code: Select all

void OnEnable(){
   Lua.RegisterFunction ("once", null, typeof(KarmaLua).GetMethod("Once"));
}

void OnDisable() {
   Lua.UnregisterFunction ("once");
}

public static double Once(double value) {

   var entry = ConversationLogger.LastEntry;
   ...
}
User avatar
Tony Li
Posts: 22108
Joined: Thu Jul 18, 2013 1:27 pm

Re: Getting the Dialogue node from Lua functions

Post by Tony Li »

Thanks for sharing!
Post Reply