OpenTTD GameScript API 20260206-master-g4d4e37dbf1
GSText Class Reference

Class that handles all text related functions. More...

#include <script_text.hpp>

Inheritance diagram for GSText:

Public Member Functions

 GSText (StringID string,...)
 Generate a text from string.
void SetParam (int parameter, object value)
 Set the parameter to a value.
GSTextAddParam (object value)
 Add a value as parameter (appending it).

Detailed Description

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:

local text = GSText(GSText.STR_NEWS);
text.AddParam(1);
GSText(StringID string,...)
Generate a text from string.

This will set the {COMPANY} to the name of Company 1. Alternatively you can directly give those arguments to the GSText constructor, like this:

local text = GSText(GSText.STR_NEWS, 1);

Constructor & Destructor Documentation

◆ GSText()

GSText::GSText ( StringID string,
... )

Generate a text from string.

You can set parameters to the instance which can be required for the string.

Parameters
stringThe string of the text.
...Optional arguments for this string.

Member Function Documentation

◆ AddParam()

GSText * GSText::AddParam ( object value)

Add a value as parameter (appending it).

Parameters
valueThe value of the parameter. Has to be string, integer or an instance of the class GSText.
Returns
The same object as on which this is called, so you can chain.

◆ SetParam()

void GSText::SetParam ( int parameter,
object value )

Set the parameter to a value.

Parameters
parameterWhich parameter to set.
valueThe value of the parameter. Has to be string, integer or an instance of the class GSText.