OpenTTD GameScript API
20241117-master-ga6c526cfa0
|
Class that handles all text related functions. More...
Public Member Functions | |
GSText (StringID string,...) | |
Generate a text from string. More... | |
void | SetParam (int parameter, object value) |
Set the parameter to a value. More... | |
GSText * | AddParam (object value) |
Add a value as parameter (appending it). More... | |
Static Public Attributes | |
static const int | SCRIPT_TEXT_MAX_PARAMETERS = 20 |
The maximum amount of parameters you can give to one object. | |
Class that handles all text related functions.
You can define a language file in lang/english.txt, in the same format as OpenTTD does, including tags like {BLACK}, {STRING1} etc. The name given to this string is made available to you in GSText, for example: GSText.STR_NEWS, if your english.txt contains: STR_NEWS :{BLACK}Welcome {COMPANY}!
In translation files like lang/dutch.txt you can then translate such strings, like: STR_NEWS :{BLACK}Hallo {COMPANY}! When the user has the dutch language selected, it will automatically use the translated string when available. The fallback language is always the english language.
If you use parameters in your strings, you will have to define those parameters, for example like this:
This will set the {COMPANY} to the name of Company 1. Alternatively you can directly give those arguments to the GSText constructor, like this:
GSText::GSText | ( | StringID | string, |
... | |||
) |
Generate a text from string.
You can set parameters to the instance which can be required for the string.
string | The string of the text. |
... | Optional arguments for this string. |
GSText* GSText::AddParam | ( | object | value | ) |
Add a value as parameter (appending it).
value | The value of the parameter. Has to be string, integer or an instance of the class GSText. |
void GSText::SetParam | ( | int | parameter, |
object | value | ||
) |
Set the parameter to a value.
parameter | Which parameter to set. |
value | The value of the parameter. Has to be string, integer or an instance of the class GSText. |