evaluating variables in dialogueEntries

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
urrmurrmur
Posts: 47
Joined: Wed May 05, 2021 1:57 pm

evaluating variables in dialogueEntries

Post by urrmurrmur »

Hi,

I am trying to display dialogue entries in a custom UI. What I am doing at the moment is using roughly the following code:

Code: Select all

Conversation conversation = DialogueManager.masterDatabase.GetConversation( "conversationName" );
List<DialogueEntry> dialogueEntries = conversation.dialogueEntries;
myUIComponent.text = dialogueEntries[curIndex].currentDialogueText;
This works perfectly, as long as currentDialogueText is a simple string without any sort of markup. However, I have some dialogue entries which contain variables. Example:

"[var=drainGridsSeen] grids found"

drainGridsSeen is a number tracking the amount of grids a player has found. When this string is shown in my UI, it is displayed as is, including the "[var=drainGridsSeen]" part. When it is displayed in the DSFU subtitle panel, it correctly parses the variable and shows something like "3 grids found".

So my question is, how can I force DSFU to parse the entry text and replace any variables by their respective values?
User avatar
Tony Li
Posts: 22107
Joined: Thu Jul 18, 2013 1:27 pm

Re: evaluating variables in dialogueEntries

Post by Tony Li »

Hi,

Use FormattedText.ParseCode():

Code: Select all

myUIComponent.text = FormattedText.ParseCode(dialogueEntries[curIndex].currentDialogueText);
Alternatively, if this is in the context of an active conversation, I suggest using the dialogue UI system. You can provide your own UI code:
  • Duplicate TemplateDialogueUI.cs
  • Move it to your own folder and rename it
  • Enter your code where the comments indicate
  • Add it to your UI GameObject
  • Assign your UI GameObject to the Dialogue Manager's Display Settings > Dialogue UI
Or, if you don't want to do even that, create a ConversationModel to run the conversation. This will run the back-end stuff (processing Conditions and Scripts, etc.) without showing any UI or playing any sequences. It will produce Subtitle objects where the dialogue text is already parse properly.
urrmurrmur
Posts: 47
Joined: Wed May 05, 2021 1:57 pm

Re: evaluating variables in dialogueEntries

Post by urrmurrmur »

Thanks for the info.

It's not in an active conversation, it's a scene where the main character's thoughts are being visualized as text floating around his head. Each thought is created as a very small DSFU conversation (couple of entries at most), but since there's multiple thoughts active at the same time I can't just start a conversation. So I read them all and put them in thought bubbles around the head simultaneously. I think your ConversationModel suggestion would work as well (and is probably the better approach), but my code works as intended when using ParseCode, so I'm happy :D
User avatar
Tony Li
Posts: 22107
Joined: Thu Jul 18, 2013 1:27 pm

Re: evaluating variables in dialogueEntries

Post by Tony Li »

Sounds good! BTW, if you ever do need to run multiple conversations at the same time, tick the Dialogue Manager's Other Settings > Allow Simultaneous Conversations.
urrmurrmur
Posts: 47
Joined: Wed May 05, 2021 1:57 pm

Re: evaluating variables in dialogueEntries

Post by urrmurrmur »

Update to this: I decided to rework my system to use a ConversationModel after all, since I needed some scripts to be evaluated, which wasn't happening in my own system. But there's something I don't understand. a ConversationState has responses, which are divided into pc or npc responses, but those don't seem to get initialized automatically?

Example, I am currently testing this debug conversation:
dsfu_responses.png
dsfu_responses.png (30.69 KiB) Viewed 292 times
With the following code:
dsfu_response_code.png
dsfu_response_code.png (59.51 KiB) Viewed 292 times
The first iteration of the while loop works, I retrieve the state encircled in green, and the correct subtitle gets displayed. However, the state doesn't seem to have any responses. state.hasAnyResponse is false, and state.npcResponses, state.pcResponses, state.pcAutoResponse etc all return empty. I've tried it both with states that have one responses, and states that have multiple.

What I want to use it for is quite straightforward, all my conversation would only have pc states, often only one, sometimes a few, and never more than one response per state, so no choice menus are required. But apparently the ConversationModel in itself doesn't set the responses up? Or did I use it incorrectly?
User avatar
Tony Li
Posts: 22107
Joined: Thu Jul 18, 2013 1:27 pm

Re: evaluating variables in dialogueEntries

Post by Tony Li »

Hi,

When you call ConversationModel.GetState(), pass "true" for the includeLinks parameter. Otherwise it won't include links to responses (e.g., from "[var=DrainGridsSeen] roost" to "another one" and "whatsthis?").

Code: Select all

state = convo2.GetState( responses[0].destinationEntry, true );
urrmurrmur
Posts: 47
Joined: Wed May 05, 2021 1:57 pm

Re: evaluating variables in dialogueEntries

Post by urrmurrmur »

...That's one for the wall of shame. Been pouring through source code for two hours and that parameter never even registered to me somehow :?

Sorry about this one, but thanks for the help.
User avatar
Tony Li
Posts: 22107
Joined: Thu Jul 18, 2013 1:27 pm

Re: evaluating variables in dialogueEntries

Post by Tony Li »

No worries -- glad to help!
Post Reply