Page 1 of 1
OnRecordPersistentData / OnApplyPersistentData
Posted: Thu Dec 19, 2019 6:50 am
by Tetralogia
Hi,
I'd like to be able to save the state of conversations with the textline dialogue ui to return to it later. I normally use :
Code: Select all
FindObjectOfType<TextlineDialogueUI>().OnRecordPersistentData();
DialogueManager.StopConversation();
and
Code: Select all
DialogueLua.SetVariable("Conversation", "Your Conversation Title");
FindObjectOfType<TextlineDialogueUI>().OnApplyPersistentData();
But it doesn't seem to be working anymore?
Re: OnRecordPersistentData / OnApplyPersistentData
Posted: Thu Dec 19, 2019 10:32 am
by Tony Li
Hi,
Make sure it's recording the state properly:
Code: Select all
FindObjectOfType<TextlineDialogueUI>().OnRecordPersistentData();
DialogueManager.StopConversation();
Debug.Log(DialogueLua.GetVariable("DialogueEntryRecords_Your Conversation Title").asString));
The last line above should record a bunch of numbers like 3;1;0;1;2;1;4.
Then make sure it's applying that saved data properly by stepping through OnApplyPersistentData in the debugger. Places it could exit early (and not resume hte conversation) are:
- If the current scene is in the Don't Load Conversation In Scenes list.
- If the variable ("DialogueEntryRecords_Your Conversation Title") doesn't exist.
- If the variable doesn't contain a list of numbers like above.
Re: OnRecordPersistentData / OnApplyPersistentData
Posted: Wed Jan 15, 2020 12:38 pm
by Tetralogia
Hi,
Sorry it took me so long to answer. When I type:
Code: Select all
FindObjectOfType<TextlineDialogueUI>().OnRecordPersistentData();
Visual Studio Code underlines
TextlineDialogueUI and tells me :
The type or namespace name 'TextlineDialogueUI' could not be found (are you missing a using directive or an assembly reference?)
Re: OnRecordPersistentData / OnApplyPersistentData
Posted: Wed Jan 15, 2020 1:20 pm
by Tony Li
Hi,
Put this line at the top of your script:
Code: Select all
using PixelCrushers.DialogueSystem.Extras;
A tip: Often when VS underlines something, you can right-click it and select the menu context menu option. This will give you options to automatically resolve the issue, such as in this case automatically adding the line shown above.
Re: OnRecordPersistentData / OnApplyPersistentData
Posted: Thu Jan 16, 2020 6:19 am
by Tetralogia
Oh sure, thanks!
So now, how do I make sure the variable
DialogueEntryRecords_MyConversation exists? I've written the method as you've suggested :
Code: Select all
void SaveConversation(string conversationTitle)
{
FindObjectOfType<TextlineDialogueUI>().OnRecordPersistentData();
DialogueManager.StopConversation();
Debug.Log(DialogueLua.GetVariable("DialogueEntryRecords_" + conversationTitle).asString);
}
And when I call it at the last node of a conversation, for example
SaveConversation("Vanessa"), the console logs :
TextlineDialogueUI.OnRecordPersistentData: Saving current conversation to DialogueEntryRecords_nil
Dialogue System: Ending Conversation
nil
I have two TextlineDialogueUI's in my scene and use an OverrideDialogueUI component on my NPCs, maybe the issue comes from that?
Re: OnRecordPersistentData / OnApplyPersistentData
Posted: Thu Jan 16, 2020 7:58 am
by Tony Li
Yes, FindObjectOfType with the 2 TextlineDialogueUIs is probably the issue. It's probably finding the wrong one. If only one conversation is active at a time, the easiest way to find the correct UI is:
Code: Select all
TextlineDialogueUI ui = DialogueManager.displaySettings.dialogueUI.GetComponent<TextlineDialogueUI>();
In the message "Saving current conversation to DialogueEntryRecords_nil", 'nil' means the value of the "Conversation" variable isn't set. That's something else to check.
Re: OnRecordPersistentData / OnApplyPersistentData
Posted: Thu Jan 16, 2020 9:02 am
by Tetralogia
Ok! I figured that I should register the conversation variable myself, so I rewrote my OpenConversation() method:
Code: Select all
void OpenConversation(string conversationName, double playerIndex, double conversantIndex, double ui)
{
int player = (int)playerIndex;
int conversant = (int)conversantIndex;
int uiIndex = (int) ui;
if(DialogueManager.ConversationHasValidEntry(conversationName))
{
DialogueLua.SetVariable("Conversation", conversationName);
textlineDialogueUIs[uiIndex].GetComponent<TextlineDialogueUI>().OnApplyPersistentData();
DialogueManager.StartConversation(conversationName, Characters.charactersTransforms[player], Characters.charactersTransforms[conversant]);
}
}
So when I call SaveConversation():
Code: Select all
void SaveConversation(string conversationTitle, double ui)
{
int uiIndex = (int) ui;
textlineDialogueUIs[uiIndex].GetComponent<TextlineDialogueUI>().OnRecordPersistentData();
DialogueManager.StopConversation();
Debug.Log(DialogueLua.GetVariable("DialogueEntryRecords_" + conversationTitle).asString);
}
I now get a series of numbers. I still have one issue. For exemple, in one of my conversation, I call SaveConversation() on the DialogueEntry 24, but my DialogueEntryRecords ends with 3;23 and not 3;24. So, when I reopen the conversation, it replays the node 24, calls SaveConversation() and thus closes the conversation immediately.
Re: OnRecordPersistentData / OnApplyPersistentData
Posted: Thu Jan 16, 2020 10:26 am
by Tony Li
When resuming, TextlineDialogueUI replays the entry that it was saved on. If you can change SaveConversation() to sequencer command, you can make TextlineDialogueUI skip it by ticking the Save/Load > Don't Repeat Last Sequence checkbox.
Otherwise, if you want to keep it as a Lua-registered function, you could set a bool before resuming the conversation. If the bool is true (because the conversation is being resumed), exit the function instead of stopping and saving the conversation.
Re: OnRecordPersistentData / OnApplyPersistentData
Posted: Thu Jan 16, 2020 1:00 pm
by Tetralogia
I need it as a Lua-registered function so I took the second solution:
Code: Select all
void SaveConversation(string variable, string conversationTitle, double ui)
{
int uiIndex = (int) ui;
if(DialogueLua.GetVariable(variable).asBool == false) {
textlineDialogueUIs[uiIndex].GetComponent<TextlineDialogueUI>().OnRecordPersistentData();
DialogueManager.StopConversation();
DialogueLua.SetVariable(variable, true);
}
}
Thank you a lot for your help!
Re: OnRecordPersistentData / OnApplyPersistentData
Posted: Thu Jan 16, 2020 1:03 pm
by Tony Li
Glad to help!