Page 1 of 1

Best way to trigger a line of dialogue through code?

Posted: Fri Apr 01, 2016 12:07 am
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.

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

Posted: Fri Apr 01, 2016 9:57 am
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);
}

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

Posted: Mon Apr 04, 2016 10:14 pm
by hannah
Awesome! That worked great!

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

Posted: Mon Apr 04, 2016 10:22 pm
by Tony Li
Great! Glad I could help.