Restarting dialogue but preserving old responses

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
devalus
Posts: 52
Joined: Tue Feb 20, 2018 5:09 pm

Restarting dialogue but preserving old responses

Post by devalus »

Hi Tony!

Hope you are well, it's me again :shock:

So I'm trying to achieve this effect:
Player restarts the game but responses picked in the past are displayed.

I'm using Textline with typewriter effects.
I have Input Settings > Tag for Old Responses set.

I've tried:
1. Resetting the dialogue
I use DialogueManager.ResetDatabase(DatabaseResetOptions.RevertToDefault) which resets the dialogue and variables, but the old responses are no longer marked.

2. Triggering the first conversation
When I do this it just loads the end of the first conversation as expected.

Basically, I'm not sure how to restart the dialogue without wiping out the save data. Would be super helpful if you could point me in the right direction :)

Cheers,
Amy
User avatar
Tony Li
Posts: 22055
Joined: Thu Jul 18, 2013 1:27 pm

Re: Restarting dialogue but preserving old responses

Post by Tony Li »

Hi Amy,

The conversation history is stored in a Dialogue System variable.

If you only have one conversation and the Textline Dialogue UI's "Use Conversation Variable" checkbox is unticked, then the variable is named "DialogueEntryRecords".

Otherwise the variable for the conversation is named "DialogueEntryRecords_conversation" where conversation is the name of the conversation. Replace spaces and other special characters with underscores. So the variable for the conversation "John Doe" would be "DialogueEntryRecords_John_Doe".

To clear the conversation history, delete the variable. You can do this in a Dialogue System Trigger (Add Action > Run Lua Code):

Code: Select all

Variable["DialogueEntryRecords_John_Doe"] = nil
or in C#:

Code: Select all

DialogueLua.SetVariable("DialogueEntryRecords_John_Doe", string.Empty);
devalus
Posts: 52
Joined: Tue Feb 20, 2018 5:09 pm

Re: Restarting dialogue but preserving old responses

Post by devalus »

Hi Tony!

Thanks for the super fast response.

I think I was a bit vague in my post.

By "responses picked in the past are displayed" I meant the old responses should appear greyed out (which I've set in Input Settings > Tag for Old Responses). This way when the player restarts a game they know what choices they have made in the past.

I tried clearing the DialogueEntryRecords_conversation variable and was able to restart the conversation, however the past choices are no longer indicated, similar to what happens when I reset the dialogue with DialogueManager.ResetDatabase(DatabaseResetOptions.RevertToDefault).



Actually I just realized the old responses tag is gone after reloading the game. So I'm guessing the state is just not being saved to begin with?


Cheers,
Amy
User avatar
Tony Li
Posts: 22055
Joined: Thu Jul 18, 2013 1:27 pm

Re: Restarting dialogue but preserving old responses

Post by Tony Li »

Hi Amy,

Roughly speaking, the Dialogue System maintains three sets of data:

1. Old responses (aka SimStatus).

2. Variables (e.g., decisions the player has made).

3. Conversation histories (via TextlineDialogueUI) which are saved in variables.


Old responses are included in saved games if the Dialogue Manager's Other Settings > Include SimStatus checkbox is ticked.

Normally when the player starts a new game it resets all data.

If I understand correctly, when the player starts a new game (instead of continuing their current game), you want the data to work like this:

1. Old responses: KEEP.

2. Variables: RESET.

3. Conversation histories: RESET.

Please let me know if this is the case. If so, I'll try to think of a good way to handle it.
devalus
Posts: 52
Joined: Tue Feb 20, 2018 5:09 pm

Re: Restarting dialogue but preserving old responses

Post by devalus »

Yes this is exactly what I'm trying to achieve!
Tony Li wrote: Mon Jul 15, 2019 5:15 pm 1. Old responses: KEEP.

2. Variables: RESET.

3. Conversation histories: RESET.
Also thanks for letting me know about the SimStatus checkbox!
User avatar
Tony Li
Posts: 22055
Joined: Thu Jul 18, 2013 1:27 pm

Re: Restarting dialogue but preserving old responses

Post by Tony Li »

I think this should work:

Code: Select all

using System.Text;
using PixelCrushers.DialogueSystem;
...
public void ResetAllDataExceptSimStatus()
{
    // Save SimStatus:
    var sb = new StringBuilder();
    PersistentDataManager.AppendConversationData(sb);
    var simStatusData = sb.ToString();
    
    // Reset all data except keep SimStatus:
    PersistentDataManager.ApplySaveData(simStatusData);
}
devalus
Posts: 52
Joined: Tue Feb 20, 2018 5:09 pm

Re: Restarting dialogue but preserving old responses

Post by devalus »

This is fantastic, works exactly as I hoped! Thank you Tony :)

A follow-up question about SimStatus:
So I have a skip button that fast forwards conversations. I'm trying to make it only skip previously viewed dialogues and stop at new ones. (Currently it's just skipping everything.)

I thought I could do this by checking each subtitle's SimStatus OnConversationLine with DialogueLua.GetSimStatus(subtitle.dialogueEntry) == "WasDisplayed". But of course, once this is triggered the SimStatus has already switched to WasDiaplayed so didn't work.

So my question is, is there a different way I can check the SimStatus that happens right before the subtitle is called?

Cheers,
Amy
User avatar
Tony Li
Posts: 22055
Joined: Thu Jul 18, 2013 1:27 pm

Re: Restarting dialogue but preserving old responses

Post by Tony Li »

Hi Amy,

OnPrepareConversationLine(DialogueEntry) is called before updating SimStatus. You could do something like this:

Code: Select all

bool isCurrentLineOld;

void OnPrepareConversationLine(DialogueEntry entry)
{
    isCurrentLineOld = DialogueLua.GetSimStatus(entry) == "WasDisplayed;
}

void OnConversationLine(Subtitle subtitle)
{
    if (isCurrentLineOld) subtitle.sequence = "Continue()"; // Immediately skip to next line.
}
devalus
Posts: 52
Joined: Tue Feb 20, 2018 5:09 pm

Re: Restarting dialogue but preserving old responses

Post by devalus »

Exactly what I was looking for, thank you so much as always Tony :D
User avatar
Tony Li
Posts: 22055
Joined: Thu Jul 18, 2013 1:27 pm

Re: Restarting dialogue but preserving old responses

Post by Tony Li »

Glad I could help! :-)
Post Reply