Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes

ScriptText Class Reference

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

#include <script_text.hpp>

Inheritance diagram for ScriptText:
Text ZeroedMemoryAllocator ScriptObject SimpleCountedObject

Public Member Functions

 ScriptText (HSQUIRRELVM vm)
 The constructor wrapper from Squirrel.
SQInteger _set (HSQUIRRELVM vm)
 Used for .param_N and [] set from Squirrel.
SQInteger SetParam (HSQUIRRELVM vm)
 Set the parameter.
SQInteger AddParam (HSQUIRRELVM vm)
 Add an parameter.
const char * GetEncodedText ()

Static Public Attributes

static const int SCRIPT_TEXT_MAX_PARAMETERS = 20
 The maximum amount of parameters you can give to one object.

Private Member Functions

char * _GetEncodedText (char *p, char *lastofp)
 Internal function for recursive calling this function over multiple instances, while writing in the same buffer.
SQInteger _SetParam (int k, HSQUIRRELVM vm)
 Set a parameter, where the value is the first item on the stack.

Private Attributes

StringID string
char * params [SCRIPT_TEXT_MAX_PARAMETERS]
int parami [SCRIPT_TEXT_MAX_PARAMETERS]
ScriptTextparamt [SCRIPT_TEXT_MAX_PARAMETERS]
int paramc

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 ScriptText, for example: ScriptText.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 = ScriptText(ScriptText.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 ScriptText constructor, like this:

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

game

Definition at line 70 of file script_text.hpp.


Member Function Documentation

char * ScriptText::_GetEncodedText ( char *  p,
char *  lastofp 
) [private]

Internal function for recursive calling this function over multiple instances, while writing in the same buffer.

Parameters:
p The current position in the buffer.
lastofp The last position valid in the buffer.
Returns:
The new current position in the buffer.

Definition at line 173 of file script_text.cpp.

References _GetEncodedText(), seprintf(), and Utf8Encode().

Referenced by _GetEncodedText().


The documentation for this class was generated from the following files: