Page 1 of 1

Creating a Dialogue entry in Code

Posted: Thu Apr 07, 2016 4:23 pm
by hannah
I've trying to do this myself but I don't think I'm supplying the entry with all the data it needs because the system if throwing me errors. There are some places in my game where I'd just like to have an actor speak a line of dialogue that I write in code.

Re: Creating a Dialogue entry in Code

Posted: Thu Apr 07, 2016 4:35 pm
by Tony Li
Hi,

Do you want the actor to speak it as a bark (i.e, through a bark UI) or as a subtitle (through the dialogue UI)?

Barks are easier. You need to create a Subtitle object. Then start the BarkController.Bark() coroutine.

Code: Select all

var speakerInfo = new CharacterInfo(actorID, nameInDatabase, speakerTransform, CharacterType.NPC, portraitTexture);
var listenerInfo = new CharacterInfo(/*similar parameters*/);
var formattedText = FormattedText.Parse("This is a bark!", DialogueManager.MasterDatabase.emphasisSettings);
var sequence = string.Empty; // Play this sequence while barking.
var responseMenuSequence = string.Empty; // Not used in barks.
DialogueEntry dialogueEntry = null;
var subtitle = new Subtitle(speakerInfo, listenerInfo, formattedText, sequence, responseMenuSequence, dialogueEntry);
StartCoroutine(BarkController.Bark(subtitle)); 
To play it as a subtitle, you can either create a conversation on the fly and start it:

Code: Select all

var conversation = new Conversation(/*etc.*/);
DialogueManager.MasterDatabase.conversations.Add(conversation);
DialogueManager.StartConversation("title", actor, conversant); 
Or manually open the dialogue UI with IDialogueUI.Open(), create a Subtitle object like above and call IDialogueUI.ShowSubtitle, and then when the sequence is done (or whenever is the right time), call IDialogueUI.Close() to close the dialogue UI.


If I completely misunderstood you, and you simply want to use your own code to set the Dialogue Text of an existing conversation's dialogue entry, that's much easier! Register a Lua function. Then use the [lua] tag to call that function in your Dialogue Text:
  • Dialogue Text: "[lua( MyDynamicTextFunction() )]"

Re: Creating a Dialogue entry in Code

Posted: Fri Apr 08, 2016 5:35 pm
by hannah
bark will be perfect! trying this now.

Re: Creating a Dialogue entry in Code

Posted: Fri Apr 08, 2016 5:43 pm
by hannah
I'm getting an error that 'emphasisSettings' doesn't exist in DisplaySettings.

"DialogueManager.DisplaySettings.emphasisSettings"

Re: Creating a Dialogue entry in Code

Posted: Fri Apr 08, 2016 6:42 pm
by Tony Li
Oops, typo. My fingers must have disconnected from my brain for a sec. It should be DialogueManager.MasterDatabase.emphasisSettings. I'll fix that in my post above, too.