Nested variables

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
perezbalen
Posts: 40
Joined: Mon May 24, 2021 7:22 pm

Nested variables

Post by perezbalen »

HI

I'm new to this, and still figuring stuff out. So forgive me if this is trivial.
I'm trying to get the dialogue to display a variable with a variable inside.

Basically, I have two variables.
Var1, called "SCORE", with the value "300"
Var2, called "ScoreMessageText", with the vaulie:

Code: Select all

[em3]This is your score:[var=SCORE] points.[/em3]
In a Conversation, if I put the Dialogue text as:

Code: Select all

Let me tell you your score: [em3]This is your score:[var=SCORE] points.[/em3] 
It displays what you'd expect:
Let me tell you your score: This is your score:300 points.
But if, in a conversation, I put:

Code: Select all

Let me tell you your score: [var=ScoreMessageText] 
I get this:
Let me tell you your score: This is your score:[var=SCORE] points.
So, is what I'm trying to do possible?
User avatar
Tony Li
Posts: 22049
Joined: Thu Jul 18, 2013 1:27 pm

Re: Nested variables

Post by Tony Li »

Hi,

The [var=variable] markup tag isn't recursive. It doesn't handle nested variables.

As an alternative, you can use the [lua(code)] markup tag and the string.format() function.
(In the Dialogue System's default Lua version, string.format() uses the same format codes as C#'s string.Format() method.)

Say your variables are:
  • Variable["SCORE"] = 300
  • Variable["ScoreMessageText"] = "This is your score: {0} points"
Then you can set your Dialogue Text to:
  • Dialogue Text: "Let me tell you your score.
    [em3][lua(string.format(Variable["ScoreMessageText"], Variable["SCORE"]))][/em3]"
perezbalen
Posts: 40
Joined: Mon May 24, 2021 7:22 pm

Re: Nested variables

Post by perezbalen »

Thanks. It worked like a charm.
User avatar
Tony Li
Posts: 22049
Joined: Thu Jul 18, 2013 1:27 pm

Re: Nested variables

Post by Tony Li »

Glad to help!
Post Reply