OpenTTD GameScript API  20240328-master-gca53e134be
Public Member Functions | Static Public Attributes
GSText Class Reference

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

Inheritance diagram for GSText:

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...
 
GSTextAddParam (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.
 

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);

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.
GSText::GSText
GSText(StringID string,...)
Generate a text from string.
GSText
Class that handles all text related functions.
Definition: script_text.hpp:32