Best way to trigger a line of dialogue through code?

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
hannah
Posts: 17
Joined: Mon Feb 22, 2016 10:42 pm

Best way to trigger a line of dialogue through code?

Post by hannah »

So here's the scenario. The player comes to a point in the conversation where they're asked if they know how to play poker. There's a face down card and if the player clicks on it I'd like that to count as a response and trigger a dialogue tree inside the current conversation.
User avatar
Tony Li
Posts: 21678
Joined: Thu Jul 18, 2013 1:27 pm

Re: Best way to trigger a line of dialogue through code?

Post by Tony Li »

Hi,

Here are two options:

1. Set up your card to call the dialogue UI's "OnClick" method. You'll need to pass a Response object. For example:

Code: Select all

void OnMouseDown() {
    var formattedText = FormattedText.Parse("This is the response text.", DialogueManager.MasterDatabase.emphasisSettings);
    var dialogueEntry = DialogueManager.MasterDatabase.GetDialogueEntry(conversationID, dialogueEntryID);
    var response = new Response(formattedText, dialogueEntry);
    var dialogueUI = FindObjectOfType<UnityUIDialogueUI>();
    dialogueUI.OnClick(response);
}
2. Or set up your card to cancel the current conversation (DialogueManager.StopConversation) and then either restart it at a specific dialogue entry (DialogueManager.StartConversation) or set a Lua variable and restart it from the beginning and branch differently based on that Lua variable. For example:

Code: Select all

void OnMouseDown() {
    DialogueManager.StopConversation();
    DialogueLua.SetVariable("clickedCard", true);
    DialogueManager.StartConversation("My Conversation", actor, conversant);
}
hannah
Posts: 17
Joined: Mon Feb 22, 2016 10:42 pm

Re: Best way to trigger a line of dialogue through code?

Post by hannah »

Awesome! That worked great!
User avatar
Tony Li
Posts: 21678
Joined: Thu Jul 18, 2013 1:27 pm

Re: Best way to trigger a line of dialogue through code?

Post by Tony Li »

Great! Glad I could help.
Post Reply