Class StringTable
From TrainzOnline
- API Hierarchy
- GSObject
- StringTable
- GSObject
- The StringTable class provides access to an asset's string table.
- Any asset can have a string table container in its config.txt file, defined in the following format:
string-table { Industry_Title "Packing Plant" Industry_Description "$0 Packing Plant" Announcement "The train at platform $0 is the $1 for $2, $3 and $4" }
- A string can have up to 10 parameters in the range of $0..$9.
- A string table parameter is identified by the percentage character '$' followed by the parameter number.
- The methods in this class allow a string to be retrieved such that its parameters are substituted with the desired string.
- String tables can be used to store segments of HTML code that can be reused with the substituted parameters to define a table for example.
- The Browser class also supports the use of string parameters through its Browser.SetParam() method.
Contents |
Methods
ClearParams
public native void ClearParams(void)
- Parameters
- None
- Returned Value
- None
- Syntax
table.ClearParams();
- Notes
- Resets the parameter list for the referenced StringTable.
GetLanguage
public native string GetLanguage(void)
- Parameters
- None
- Returned Value
- The current language version of Trainz.
- Syntax
string language = GetLanguage();
- Notes
GetString
public native string GetString(string s)
public native string GetString0(string s)
public native string GetString0(string s)
- Parameters
- s = Name of the StringTable value to retrieve.
- Returned Value
- Value of the named item.
- Syntax
// Industry_Description "Packing Plant" description = table.GetString("Industry_Description"); // returns "Packing Plant"
- Notes
- If the named value is not present an empty string is returned.
GetString#
public string GetString1(string s, string p0)
public string GetString10(string s, string p0,.., string p9)
public string GetString10(string s, string p0,.., string p9)
- Parameters
- s = Name of the StringTable value to retrieve.
- p0..p9 = Replaceable parameters identified by "$0".."$9".
- Returned Value
- None
- Syntax
// Industry_Description "$0 Packing Plant" description = table.GetString1("Industry_Description","Wagga Wagga"); // returns "Wagga Wagga Packing Plant" // Announcement "The train at platform $0 is the $1 for $2, $3 and $4" description = table.GetString5("Announcement","1","8:15","Chelmsford","Witham","Colchester"); // returns "The train at platform 1 is the 8:15 for Chelmsford, Witham and Colchester"
- Notes
- A series of methods to retrieve a named string with substitution of up to 10 replaceable parameters.
- The parameters are set up as placeholders within the StringTable using a percentage sign as an escape character.
- Just to keep things simple function name counting starts at 1 and parameter indexing starts at zero.
SetParam
public native void SetParam(int param, string text)
- Parameters
- param = Index of parameter to define.
- text = String value to assign to the defined parameter.
- Returned Value
- None
- Syntax
// Industry_Description "$0 Packing Plant" // Station_Description "$0 Station" table.SetParam(1,"Fremantle"); table.GetString("Industry_Description"); // returns "Fremantle Packing Plant" table.GetString("Station_Description"); // returns "Fremantle Station"
- Notes
- The value assigned to the parameter remains in place until amended or until a call to ClearParams() is made.