-
Notifications
You must be signed in to change notification settings - Fork 0
Extension | Template Strings
Template strings allow a programmer to forgo TorqueScript's string concatenation operators and instead include expressions inside the string itself. A template string is simply a normal string with a $ in-front of the first quotation mark, i.e. %myString = $"". To include an expression inside of a template string, the programmer can escape out of the string by using the {} operators. The programmer will put their expression inside of these characters.
We can declare a string template as so:
%variable = $"Welcome to {%client.getPlayerName()}'s server!";
This declaration will polyfill down to:
%variable = "Welcome to " @ (%client.getPlayerName()) @ "'s server!";
Another example:
%purchaseMessage = $"<br><br>\c6{%itemName} costs \c3{%item.getPrice() * %itemSale} {$MD::CurrencyName}\c6.";
polyfills to:
%purchaseMessage = "<br><br>\c6" @ (%itemName) @ " costs \c3" @ (%item.getPrice() * %itemSale) @ " " @ ($MD::CurrencyName) @ "\c6.";