Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: zurik on Sat 18/08/2018 17:46:30

Title: String variables inside the dialog
Post by: zurik on Sat 18/08/2018 17:46:30
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
Title: Re: String variables inside the dialog
Post by: Cassiebsg on Sat 18/08/2018 18:18:32
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)
Title: Re: String variables inside the dialog
Post by: Crimson Wizard on Sat 18/08/2018 18:32:40
In a regular script you do this using String.Format (http://www.adventuregamestudio.co.uk/manual/ags76.htm#String.Format).

For example:
Code (ags) Select

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 (http://www.adventuregamestudio.co.uk/manual/ags42.htm#CustomDialogOptions). 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.
Title: Re: String variables inside the dialog
Post by: zurik on Mon 20/08/2018 15:01:30
Thank you! Perfect :)