Variable in Text

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
LastEpochGame
Posts: 2
Joined: Sun May 06, 2018 1:21 pm

Variable in Text

Post by LastEpochGame »

I'm trying to create a dialogue which replaces a variable in the string with a value from another script.

If I want to create a dialogue option which says: "It will cost you X points to do that." and replace X with a value from a database or script or something. What is the best way to do that?

Thanks for your help.
-Mike
User avatar
Tony Li
Posts: 22059
Joined: Thu Jul 18, 2013 1:27 pm

Re: Variable in Text

Post by Tony Li »

Hi,

You can define a dialogue database variable named X in the Dialogue Editor window and use a [var=varName] markup tag in your text:

Code: Select all

"It will cost you [var=X] points to do that."
To set X in a C# script, use DialogueLua.SetVariable():

Code: Select all

using PixelCrushers.DialogueSystem;
...
DialogueLua.SetVariable("X", 42);
If you need to pull X from a script, register your script function with Lua. Then use the [lua(code)] markup tag:

Code: Select all

"It will cost you [lua( GetPointCost() )] points to do that."
LastEpochGame
Posts: 2
Joined: Sun May 06, 2018 1:21 pm

Re: Variable in Text

Post by LastEpochGame »

Thank you very much for your ultra speedy reply, I'll give that a shot.

-Mike
User avatar
Tony Li
Posts: 22059
Joined: Thu Jul 18, 2013 1:27 pm

Re: Variable in Text

Post by Tony Li »

Glad to help! If you have any questions about it, just let me know.
User avatar
nathanj
Posts: 303
Joined: Sat May 28, 2016 12:30 am

Re: Variable in Text

Post by nathanj »

Gotta say, this is absolutely amazing. I saw this posted weeks ago and am now just getting to implementing it. We build multiple projects off the same core files, though with different terrains, vegetation, names, language and such. So being able to change the names of generic variables so easily is such an incredibly powerful function.

We no longer need multiple databases for each project, we can have one single database that continually gets updated and improved while the variables are easily switched out for site specific jobs.

Hats off, Tony.
User avatar
Tony Li
Posts: 22059
Joined: Thu Jul 18, 2013 1:27 pm

Re: Variable in Text

Post by Tony Li »

Thanks! :D
Post Reply