How to update variables in a string when displayed?

Hello everyone,

I have a lot of strings I want to use for character dialogue. Right now I store them in a dialogue.js as public variables and grab them when needed (public var greeting : String = “Hello, mate!”:wink: and then I update the GUI with the needed string. But there’s a big problem with this method: any variables in the strings themselves (the player name, or number of items the player is carrying, etc.) remain at the same value as when the game started.

So how can I format this so it doesn’t bake the variable into the string until the dialogue is actually put on screen?

Thanks!

//Dialogue.js
var character : CharacterScript;
var greeting : String = “Hello, mate!”;

//CharacterScript.js
var name : String = "Bradley";
var coconuts : int = 0;

//GUI.js
var activeText : String = "";
GUI.Box(Rect (80,60,874,648), activeText);

//Talking.js
var dialogue : Dialogue; //set a reference here however u want(inspector is fine)
var character : CharacterScript; //set a reference here as well.
function Update()
{
	if(Input.GetKyeDown(KeyCode.Space))
	{
		GUIScript.activeText = dialogue.greeting + " You have " + character.coconuts + " coconuts!";
	}
}