[HOWTO] How To: Get Last Subtitle From SMSDialogueUI / TextlineDialogueUI Conversations
Posted: Sun Jan 16, 2022 9:57 am
Use this C# method to get the last subtitle recorded in a conversation that used SMSDialogueUI to TextlineDialogueUI. If you're using TextlineDialogueUI (i.e., the Textline project), replace instances of "SMSDialogueUI" with "TextlineDialogueUI".
Example:
Note that this method only works if you've recorded the conversation's state to the Dialogue System's memory before ending it. The Textline project does this by default. You can manually record the conversation's state by calling the dialogue UI's OnRecordPersistentData() method.
Code: Select all
private string GetLastSubtitle(string conversationTitle)
{
var dialogueUI = DialogueManager.instance.GetComponentInChildren<SMSDialogueUI>();
if (dialogueUI == null) return string.Empty;
DialogueLua.SetVariable("Conversation", conversationTitle);
if (!DialogueLua.DoesVariableExist(dialogueUI.currentDialogueEntryRecords)) return string.Empty;
var s = DialogueLua.GetVariable(dialogueUI.currentDialogueEntryRecords).AsString;
var ints = s.Split(';');
var lastConversationID = Tools.StringToInt(ints[ints.Length - 3]);
var lastEntryID = Tools.StringToInt(ints[ints.Length - 2]);
var entry = DialogueManager.masterDatabase.GetDialogueEntry(lastConversationID, lastEntryID);
if (entry == null) return string.Empty;
return entry.currentDialogueText;
}
Code: Select all
string lastMessage = GetLastSubtitle("Chat With Sally");