Script
Introduction
Clonk supports its own scripting language: C4Script.
Object definitions and scenarios can contain a script. Function calls made from scenario scripts are considered "global" calls. Function calls made within an object script are considered "local" calls.
For further information on the two types of script see
object scripts and
scenario scripts.
C4Script uses a C-style syntax. It includes
operators,
variable declarations, compound statements, conditional statements (
if) and loops (
for and
while).
Debugging
Activate the debug mode in the developer section of the game options to have additional error messages displayed. Anyone writing scripts should do this.
Functions
As in other programming languages you can define
functions in C4Script:
func CreateRock()
{
CreateObject(Rock,50,50);
return 1;
}
Variables/Parameters
Variables can hold values of type int
, bool
, string
, proplist
, array
or object
. Any parameter not directly specified in a function call will hold the default value nil
. Functions can have a maximum of ten parameters.
Comments
Scripts may contain code comments in C-style. Comment text will be completely ignored when the script is compiled for execution.
func MyFunction() // A comment until the end of the line
{
Message("This code is executed");
/* A comment in
a block */ Message("This one is executed, too");
// Message("This code is not executed");
return 1;
}
Additional Information
Libraries
Sven2, 2002-04
matthes, 2004-06