visible variables in the UI

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
tohaMem
Posts: 21
Joined: Sat Oct 07, 2023 9:05 am

visible variables in the UI

Post by tohaMem »

Hello!

I'm in the process of creating a level up system. It's based on the number of points received in the dialogue.

Image


How can I display this variables in the UI? Something like this, but only in numbers, yes

Image
User avatar
Tony Li
Posts: 21678
Joined: Thu Jul 18, 2013 1:27 pm

Re: visible variables in the UI

Post by Tony Li »

Hi,

If you want to show a variable's value in dialogue text, use the [var=variable] markup tag. Example:
  • Dialogue Text: "Your esoteric status is [var=Status.Esoteric]."
To replace [var=variable] tags in other strings, use FormattedText.ParseCode(). Example:

Code: Select all

MyTextMeshProUGUI.text = FormattedText.ParseCode("[var=Status.Esoteric]");
However, if you only need the numeric value, it's easiest in C# to use DialogueLua.GetVariable(). Example:

Code: Select all

MyTextMeshProUGUI.text = DialogueLua.GetVariable("Status.Esoteric").asString;
tohaMem
Posts: 21
Joined: Sat Oct 07, 2023 9:05 am

Re: visible variables in the UI

Post by tohaMem »

oh, thank you! All worked! :)

And another question! How can I extract variables from DS and add/subtract them in C#?
User avatar
Tony Li
Posts: 21678
Joined: Thu Jul 18, 2013 1:27 pm

Re: visible variables in the UI

Post by Tony Li »

Hi,

Use DialogueLua.GetVariable() and DialogueLua.SetVariable(). Example:

Code: Select all

// Add +1 to Esoteric:
DialogueLua.SetVariable(DialogueLua.GetVariable("Status.Esoteric").asInt + 1);
Alternatively, you can make a property:

Code: Select all

public int Esoteric
{
    get { return DialogueLua.GetVariable("Status.Esoteric").asInt; }
    set { DialogueLua.SetVariable("Status.Esoteric", value); }
}
Post Reply