[HOWTO] How To: Get Last Subtitle From SMSDialogueUI / TextlineDialogueUI Conversations

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
User avatar
Tony Li
Posts: 22154
Joined: Thu Jul 18, 2013 1:27 pm

[HOWTO] How To: Get Last Subtitle From SMSDialogueUI / TextlineDialogueUI Conversations

Post by Tony Li »

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".

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;
}
Example:

Code: Select all

string lastMessage = GetLastSubtitle("Chat With Sally");
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.
Post Reply