Page 1 of 1

Question on Persistence Data

Posted: Wed Nov 27, 2024 1:03 pm
by CluelessGD
Hi,

First of all, thank you for the Dialogue System, It's been very helpful for first time developer like me to quickly iterate on new ideas.

I have some question regarding the persistence data.
I am building similar in concept to the Lobby in Textline extras where player can have chat simultaneously between different participants. I understand how the lobby works but for my use case I want the conversation happen on the same scene.

The closest thing that I managed so far is using PersistentDataManager.Record() to save the converastion state and use PersistentDataManager.Apply() to restore the conversation state. However, my limitation is I can only save/restore one Conversation in the same scene. My question, how would the approach be if I want save and restore multiple conversation in the same scene?

Thank you

Re: Question on Persistence Data

Posted: Wed Nov 27, 2024 4:24 pm
by Tony Li
Hi,

If you inspect the dialogue UI's TextlineDialogueUI component (which is really just an alias for SMSDialogueUI), you'll see that Use Conversation Variable is ticked. This tells TextlineDialogueUI to save each conversation's data under its own conversation variable. To make this work, set the variable "Conversation" to a unique value for each conversation -- typically the conversation's Title.

For example, if you use a Dialogue System Trigger to start "Conversation A", use two actions:

- Run Lua Code: Variable["Conversation"] = "A";
- Start Conversation: Conversation A

And for "Conversation B"'s Dialogue System Trigger:

- Run Lua Code: Variable["Conversation"] = "B";
- Start Conversation: Conversation B

Re: Question on Persistence Data

Posted: Wed Nov 27, 2024 8:46 pm
by CluelessGD
Hey Toni,

Thanks for the answer, for the implementation I am a bit lose. So I run the code in the Dialog Trigger and should I use that variable as condition if I want to restore the previous dialogue state?

Thank you agian

Re: Question on Persistence Data

Posted: Wed Nov 27, 2024 10:25 pm
by Tony Li
The way SMSDialogueUI (aka TextlineDialogueUI) works is a bit circuitous.

SMSDialogueUI has two important methods: SaveConversation() and ResumeConversation("title"). Above, I recommended using a Dialogue System Trigger. But on second thought it will be simpler to use these methods.

Let's say you have a conversation titled "Ann Chat".

Here's an example of how to start this conversation:

startConversation.png
startConversation.png (73.22 KiB) Viewed 1697 times

Note: If you let this conversation play to the end until it ends normally, it won't save the conversation (since it's done). This is why the Textline example conversations end on a node whose Sequence is "WaitForMessage(Forever)". Since nothing sends the message "Forever", the conversation stops on this node forever.

Instead, to save and exit a conversation, use this method:

saveAndExitConversation.png
saveAndExitConversation.png (93.26 KiB) Viewed 1697 times

A few notes:
  • Remember to tick the SMSDialogueUI's Use Conversation Variable checkbox.
  • The UI Buttons call the SMSDialogueUI's ResumeConversation() and StopConversation() methods that I mentioned above. ResumeConversation() will start a conversation from the beginning if there's no existing save data for it. If there is save data, it will resume it from the saved point.
  • Note that since I used UI Buttons to call the methods, I put the UI Buttons in the Dialogue Manager's hierarchy. This allows it to stay connected to the Dialogue Manager (and its SMSDialogueUI) across scene changes. The button that starts the conversation hides its Canvas. I added a Back Button to the SMSDialogueUI that saves and exits the current conversation and also shows the other Canvas again.

Re: Question on Persistence Data

Posted: Thu Nov 28, 2024 4:06 am
by CluelessGD
Wow thank you so much Tony! It works as intended. I'm almost pulling my hair, you save me so much hair.

I'll ask again if I have any issue. Sending my best regards to you!

Re: Question on Persistence Data

Posted: Thu Nov 28, 2024 8:59 am
by Tony Li
Glad to help!