String Tables

From C4 Engine Wiki
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

String tables are used by the C4 Engine to store human-readable text strings in resources that are external to the engine code and game code. The use of string tables is not required, but they can be convenient for storing strings separately in order to make localization easy and allow text to be changed without the need to recompile your game.

String Table Resources

String table resources have the .str file extension and reside inside subfolders of the Data directory. These files are stored in a binary format and are created by using the String Importer tool to import text files from the Import directory.

A string table resource is loaded by constructing a StringTable class with the name of the resource, omitting the top-level folder name inside the Data folder. Strings can be retrieved from the string table by calling the StringTable::GetString() function with a StringID object containing the identifier(s) for the string. For example, a string having the identifier 'type' can be retrieved using the following code.

const char *string = stringTable->GetString(StringID('type'));

A string nested within a hierarchy can be retrieved by adding more types to the StringID object as in the following code.

const char *substring = stringTable->GetString(StringID('type', 'abcd'));

Up to five identifiers can be specified.

See Also