Page 1 of 1

Nested variables

Posted: Mon May 24, 2021 7:40 pm
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?

Re: Nested variables

Posted: Mon May 24, 2021 9:49 pm
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]"

Re: Nested variables

Posted: Mon May 24, 2021 10:30 pm
by perezbalen
Thanks. It worked like a charm.

Re: Nested variables

Posted: Mon May 24, 2021 10:43 pm
by Tony Li
Glad to help!