Page 1 of 1
Variable in Text
Posted: Sun May 06, 2018 1:24 pm
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
Re: Variable in Text
Posted: Sun May 06, 2018 2:34 pm
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."
Re: Variable in Text
Posted: Sun May 06, 2018 3:06 pm
by LastEpochGame
Thank you very much for your ultra speedy reply, I'll give that a shot.
-Mike
Re: Variable in Text
Posted: Sun May 06, 2018 3:25 pm
by Tony Li
Glad to help! If you have any questions about it, just let me know.
Re: Variable in Text
Posted: Thu May 17, 2018 8:37 pm
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.
Re: Variable in Text
Posted: Thu May 17, 2018 8:48 pm
by Tony Li
Thanks!