Syntax

A script tells the computer what to do under which circumstances. It consists of objects and functions. Objects are the things that are used in the project, like a number (variable), a text, a screen image (bitmap) and so on. Functions determine the behavior of objects by dynamically modifying their properties at run time. An object is defined by giving its type, its name, and an initial value in the script file, like this:
type name = value;
type name = { ... }
The second line is for assembled objects, called structs, that contain not only a single value, but many parameters, given between the winged brackets. An object name may consist of up to 30 letters. The case does not matter in C-Script, but matters in lite-C, C, or C++. Names must not begin with numbers nor contain any special characters except the underscore _ , nor are you allowed to define the same name twice for different objects. Also take care that you not use a name which is already reserved for an engine variable or a object parameter.

The semicolon ';' terminates a 'logical line'. Therefore, a script line can contain several logical lines, or a logical line can be spread over several script lines. The limit is 8000 characters and 500 elements per logical line.

The most often encountered script object is a variable - an element that stores numbers. A group of three numbers - often used in 3D arithmetics - is called a vector, a group of many number is called an array. Example:

var myvariable = 123.456;  

A special kind of a variable is a flag. That's a binary value, like a switch, which can be set to on (1) or off (0). Another special object is a STRING - that one does not store a number but a sequence of characters - a piece of text - within quotation marks. Example for defining an initialized string pointer:

STRING* mystring = "It is now time for all good men...";

Note the '*' pointer suffix that is required in lite-C, but must be omitted in C-Script. When code differs between both languages in examples, the differences are marked in green for lite-C and red for C-Script.

A special kind of a string is a file name that assigns the content of a file to the given object. File names must not be longer than 20 characters and must not contain spaces or a path. The kind of file is apparent from the extension. The script language supports image files (like .PCX, .BMP, .TGA, or .DDS) for bitmaps or sprites, .MDL for models, .WMB for map entities, .HMP for terrain, .MID for songs, .WAV or .OGG for sound effects, .AVI or .MPG for movies, .FX for shaders, .WDL for C-Script and .C for lite-C scripts. This is an example for a bitmap object that is defined by a file name that determines its content:

BMAP* mybitmap = "billboard.tga";

The following special characters are valid within the script:

; Semicolon terminates each instruction or logical line.
{...} Winged brackets enclose structs or instruction lists.
(..,..) Function parameters are given in parentheses and separated by commas.
"..." Text or file names are given between quotation marks.
[...] Array or vector indices are giving between square brackets.
//... Comment until the end of the line. A script must not end with a comment.
/*...*/ Comment block. A script must not end with an open comment block.

Each programming language is unforgiving to syntax errors. Every forgotten or superfluous comma or semicolon will almost certainly produce an error message at start-up. So be carefully. In some old C-scripts you might find objects, instructions or variables that were abandoned or replaced by newer versions, and thus are not documented here anymore. Do not use them for your own scripts. Use only objects that are either described here, or defined by yourself.Features that are only available in the Extra, Commercial or Professional Edition or above are marked with mit , , or .

Naming Convention

Names are case sensitive in lite-C, and case insensitive in C-Script. For making your code easier to read, we recommend a convention for naming variables and objects. We're writing #defines in UPPERCASE, local variables as well as engine and template variables in lowercase with underscore (my_variable) and global variables with a type prefix and Mixed Case (myVariable). Here's an example for type prefixes:

Type Prefix Example
var - myVariable
long, int i iMyInteger
char chr chrMyChar
short s sMyShort
float f fMyFloat
double d dMyDouble
VECTOR vec vecVelocity
COLOR col colLight
STRING* str strMyString
BMAP* bmp bmpMyBmap
SOUND* snd sndMySound
PANEL* pan panMyPanel
TEXT* txt txtMyText
ENTITY* ent entMyEntity

If you are using several code modules in your script, add a module prefix to your variables and functions. For instance in the default.c module we've prefixed all variables with 'def_'.

See also:

Variables, Pointers, Structs, Functions,

 

► latest version online