Best approach for syncing variables

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
pixel-reverie
Posts: 15
Joined: Sun Oct 13, 2019 12:48 am

Best approach for syncing variables

Post by pixel-reverie »

Hi (Sorry for another question so soon!)

I'm wondering what the best approach is for syncing dialogue variables with my own class variables.

In my example case I am working on NPCs.
NPCs have various attributes, and most attributes I want to use in the conversations as conditions.

For example: friendshipLevel, wasTalkedToToday, hasMet etc

I dont want them to ONLY be in the conversation system, but at the same time I do want them to be in there (or easily accessible from there)

Thanks!
User avatar
Tony Li
Posts: 21965
Joined: Thu Jul 18, 2013 1:27 pm

Re: Best approach for syncing variables

Post by Tony Li »

Here are two approaches. You can pick whichever one is most convenient for you:

1. Write "get" and "set" methods to access your C# script variables. Register these methods with Lua. (See: Lua and Registering Functions.) Use those methods in the Conditions and Script fields of your dialogue entry nodes.

2. Or add a script with OnConversationStart and OnConversationEnd methods. (See Special Script Methods.) This script must be on the Dialogue Manager or one of the conversation's primary participants. In OnConversationStart, use DialogueLua.SetVariable() to set Dialogue System variables to the same values are you C# script variables. In OnConversationEnd, use DialogueLua.GetVariable() to get the values from the Dialogue System and copy them back to your C# script variables.

A convenient thing about approach #2 is that you can predefine the variables in the Dialogue Editor's Variables section so you can use the "..." dropdowns in the Conditions and Script fields without having to type anything. But the drawback is that they're only sync'ed when the conversation starts and ends.
Post Reply