Creating a Dialogue entry in Code

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

Creating a Dialogue entry in Code

Post 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.
User avatar
Tony Li
Posts: 21678
Joined: Thu Jul 18, 2013 1:27 pm

Re: Creating a Dialogue entry in Code

Post 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() )]"
hannah
Posts: 17
Joined: Mon Feb 22, 2016 10:42 pm

Re: Creating a Dialogue entry in Code

Post by hannah »

bark will be perfect! trying this now.
hannah
Posts: 17
Joined: Mon Feb 22, 2016 10:42 pm

Re: Creating a Dialogue entry in Code

Post by hannah »

I'm getting an error that 'emphasisSettings' doesn't exist in DisplaySettings.

"DialogueManager.DisplaySettings.emphasisSettings"
User avatar
Tony Li
Posts: 21678
Joined: Thu Jul 18, 2013 1:27 pm

Re: Creating a Dialogue entry in Code

Post 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.
Post Reply