Saving Custom Conversation Field

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
JuSt
Posts: 7
Joined: Wed Jul 13, 2022 6:49 pm

Saving Custom Conversation Field

Post by JuSt »

Hi there,
I'm currently working on implementing the DialogueSystem in my game. I've bumped into an issue with saving a custom field for my conversation settings.

To save anything dialogue related I use this in my custom save script

Code: Select all

dialogueSaveData = PixelCrushers.DialogueSystem.PersistentDataManager.GetSaveData()
I then load it again upon reloading the game with

Code: Select all

PersistentDataManager.ApplySaveData(dialogueSaveData)
My DialogueSystemController settings look like this:
Image

Saving works fine, except when I try to save a custom field each of my conversations has (the DisplayCount). It gets updated correctly each time the conversation is loaded, but somehow doesn't get saved.
Image

Do you have any suggestions on what I need to change to get this to work? I'm happy to provide additional info if it helps.
Thanks for any help you can provide :)
Attachments
conversation.png
conversation.png (64.51 KiB) Viewed 332 times
dialoguesystem.png
dialoguesystem.png (125.27 KiB) Viewed 332 times
User avatar
Tony Li
Posts: 21975
Joined: Thu Jul 18, 2013 1:27 pm

Re: Saving Custom Conversation Field

Post by Tony Li »

Hi,

How are you updating and checking the field value? Runtime values are stored in Lua. Are you accessing the Lua value or the original dialogue database value?

You can use Lua.Run() to get and set DialogueCount:

Code: Select all

Lua.Run("Conversation[5].DialogueCount = Conversation[5].DialogueCount + 1");

int count = Lua.Run("return Conversation[5].DialogueCount").asInt;
Or, to get the value using the DialogueLua class:

Code: Select all

int count = DialogueLua.GetConversationField(5, "DialogueCount").asInt;
(There isn't an equivalent DialogueLua function to set conversation fields.)

If you print out the save data, it will probably have a form similar to the text below. Here, you can see that it stored the conversation fields: (Conversation[1] highlighted in blue.)

Variable={Alert=\"\", enemiesKilled=0, hasLaunchCodes=false, password=\"\", Actor=\"\", Conversant=\"\", ActorIndex=\"\", ConversantIndex=\"\"}; Item[\"Get_the_Launch_Codes\"]={Name=\"Get the Launch Codes\", Description=\"Your squad has infiltrated the evil Emperor's weapons factory to intercept launch codes to stop the mega-weapon aimed at your homeworld.\", Success_Description=\"You get the launch codes and can redirect the weapon away from your homeworld.\", Failure_Description=\"\", State=\"unassigned\", Is_Item=false, Track=true, Trackable=true, }; Item[\"Enemy_Attack\"]={Name=\"Enemy Attack\", Pictures=\"[]\", Description=\"Sergeant Graves wants you to halt the enemy advance by taking out five of them.\", Success_Description=\"You defeated the enemy soldiers.\", Failure_Description=\"\", State=\"unassigned\", Is_Item=false, Trackable=true, Track=true, Entry_Count=1, Entry_1_State=\"active\", Entry_1=\"[var=enemiesKilled]/5 killed\", }; Conversation[1]={Title=\"Private Hart\", Description=\"This conversation occurs between the Player and Private Hart, who explains the main quest (Get the Launch Codes). Nodes' Conditions fields branch the conversation based on the current quest state.\", Actor=1, Conversant=2}; Conversation[2]={Title=\"Sergeant Graves\", Description=\"This quest runs the Enemy Attack quest.\", Actor=1, Conversant=3}; Conversation[4]={Title=\"Dead Enemy\", Description=\"This conversation demonstrates how to use the dialogue system for other kinds of interaction (searching a body). The first node moves the camera to the \\\"Down\\\" angle on the body over 1 second. The last node moves back to the original position.\", Actor=1, Conversant=5}; Conversation[5]={Title=\"Terminal\", Description=\"This conversation is for the computer terminal where the player can download the launch codes to complete the Get the Launch Codes quest. It overrides the Default Sequence to delay instead of playing voiceover (see below).\", Actor=1, Conversant=4}; Conversation[6]={Title=\"Enemy Barks\", Pictures=\"[]\", Description=\"These are one-liners barked by Enemy NPCs.\", Actor=1, Conversant=6};
JuSt
Posts: 7
Joined: Wed Jul 13, 2022 6:49 pm

Re: Saving Custom Conversation Field

Post by JuSt »

Hi Tony,
thanks a lot for the fast follow-up! I was checking the value with this:

Code: Select all

// checking value
if (selectedConversation.LookupInt("DisplayCount") > 0);

// setting value
int newDisplayCount = selectedConversation.LookupInt("DisplayCount") + 1;
PixelCrushers.DialogueSystem.Field.SetValue(selectedConversation.fields, "DisplayCount", newDisplayCount);
I have changed it now to this, which works with the save file:

Code: Select all

// checking value
if (DialogueLua.GetConversationField(selectedConversation.id, "DialogueCount").asInt > 0);

// setting value
Lua.Run("Conversation[" + selectedConversation.id + "].DialogueCount = Conversation[" + selectedConversation.id + "].DialogueCount + 1");
Just to not run into the same mistake again later, could you help me to clarify what the issue was in the initial approach? It did show up when I ran a Debug.Log in the console, but it showed neither in the conversation object (it still doesn't), nor would it save the updated value (it saves now).
User avatar
Tony Li
Posts: 21975
Joined: Thu Jul 18, 2013 1:27 pm

Re: Saving Custom Conversation Field

Post by Tony Li »

Hi,

At design time (i.e., when you're writing content in the Dialogue Editor outside of play mode), you make changes to the dialogue database asset.

At runtime (play mode), treat the dialogue database asset as read-only. You can technically make changes to it, but you shouldn't.

Instead, at runtime the Dialogue System loads dialogue database values (quest states, variables, conversation fields, etc.) into equivalent variables in its runtime Lua environment. You can make whatever changes you want to the Lua environment. When the Dialogue System changes a variable or quest state during play, it changes the Lua environment, not the dialogue database. When the Dialogue System wants to check the value of a variable, etc., it checks the Lua environment.

The save system basically returns a state capture of the Lua environment as a string. (It's a selective capture to minimize size.)
JuSt
Posts: 7
Joined: Wed Jul 13, 2022 6:49 pm

Re: Saving Custom Conversation Field

Post by JuSt »

Got it, thanks a lot for bearing with me and explaining :)
User avatar
Tony Li
Posts: 21975
Joined: Thu Jul 18, 2013 1:27 pm

Re: Saving Custom Conversation Field

Post by Tony Li »

Happy to help!
Post Reply