Guide

Sometimes you want to display variables or the results of functions in dialogues. In AYA/YAYA, this can be done simply. Write the name of a variable or function, or a formula, surrounded by parenthesis and prefixed with a %. So, %(minute) calls the minute variable, %(MenuRun) calls the MenuRun function, and %(1 + 1) displays the result of the 1 + 1.

In other languages, this is known as String Interpolation. On the AYAYA wiki, google translates this as "Embedded Elements" or "String Expansion".

Sidenote: In the english community, this has been colloquially known as "Envelopes". However, the term Envelope is more often used to refer to word groups called via string interpolation. I try not to call them envelopes anymore, because it creates ambiguity between string interpolation and word groups, but you may see it in my older work, and I also slip up now and then. But I digress.

This is a very handy feature, but it doesn't work in script input automatically! If you would like it to work in script input, you need to add a short snip of code to your OnTranslate function. This code was, as far as I know, originally written by Ponapalt. This is my modified version of it.

OnTranslate
{
	_talk = reference0
	
	//This is the bit that runs embedded elements in script input
	if reference1 == "" && reference2 == "" //If this is from script input
	{
		
		EVAL('"' + REPLACE(_talk,'"','""') + '"')
	}
	else
	{
		TOSTR(_talk)
	}
}

If you don't already have OnTranslate, you can just add this whole thing as-is. If you do have OnTranslate, you'll need to be a bit more careful and integrate this into what you already have.

If you're working from the GT Template, you'll likely have a setup like this:

OnTranslate
	{
	_talk = reference0
 	_talk = REPLACE(_talk, "Anchor 1", "\_a[anchor1]Anchor 1\_a")
 	_talk = REPLACE(_talk, "Anchor 2", "\_a[anchor2]Anchor 2\_a")
 	_talk = REPLACE(_talk, "Anchor 3", "\_a[anchor3]Anchor 3\_a")
		{
		"%(_talk)"
		}
	}

What you'll want to do is replace this bit:

		{
		"%(_talk)"
		}

With this bit:

	//This is the bit that runs embedded elements in script input
	if reference1 == "" && reference2 == "" //If this is from script input
	{
		
		EVAL('"' + REPLACE(_talk,'"','""') + '"')
	}
	else
	{
		TOSTR(_talk)
	}

The final result would look like this:

OnTranslate
{
	_talk = reference0
	_talk = REPLACE(_talk, "Anchor 1", "\_a[anchor1]Anchor 1\_a")
 	_talk = REPLACE(_talk, "Anchor 2", "\_a[anchor2]Anchor 2\_a")
 	_talk = REPLACE(_talk, "Anchor 3", "\_a[anchor3]Anchor 3\_a")
	
	//This is the bit that runs embedded elements in script input
	if reference1 == "" && reference2 == "" //If this is from script input
	{
		
		EVAL('"' + REPLACE(_talk,'"','""') + '"')
	}
	else
	{
		TOSTR(_talk)
	}
}

And that's it! What this bit of code does is escape any quotes in the string, and then use EVAL to run it, which will make the results of the embedded elements be displayed in the script.

Important note: This code does not work on AYA, and only works on YAYATc569-8 or newer as-is. You can convert from AYA to YAYA by following this guide, upgrade from old YAYA versions to new YAYA versions by following this guide, or if you're staying on an older version of YAYA, replace the EVAL command in the code you copied with this original version instead:

EVAL('"' + REPLACE(_talk,'"','" + CHR(0x22) + "') + '"')