String variables inside the dialog

Started by zurik, Sat 18/08/2018 17:46:30

Previous topic - Next topic

zurik

Hello. I didn't find the right issue in the forum, but I wonder if I can use variables in the dialog both options and text. For example:

Option Text:
Hey, what are you doing here, [NAME]?

and
Ego: Hello! What a nice car, is it a [CAR_MODEL]?

Thank you

Cassiebsg

I don't know if you can do that, never tried it.
You can however use regular code inside dialogue scripts, you just have to indent the lines (add at least one space at the start of the code line).

I'm assuming you know how to do it in code, but if not, just ask again. (nod)
There are those who believe that life here began out there...

Crimson Wizard

#2
In a regular script you do this using String.Format.

For example:
Code: ags

cEgo.Say(String.Format("Hello! What a nice car, is it a %s", CAR_MODEL));

Here the %s will be replaced with CAR_MODEL value (this may be either String variable or literal string).

As Cassiebsg said, when you are putting regular script commands in dialog scripts you need to just add couple of spaces before the command (this way AGS recognizes regular script commands within dialog).


For the option text this is complicated. You cannot put script commands right into option box, and unfortunately there is no function that would create new option text in script.
Unless I am forgetting a simplier solution, only way to do this is to use Custom dialog options rendering. This system lets you to draw dialog options in any way you like, and while doing so you may also print dynamically modified option text.


SMF spam blocked by CleanTalk