Script: Overview

This page should give you a short overview about the characteristics of C4Script in OpenClonk. It should be helpful if you either know some programming and quickly want to see how C4Script feels like or if you come from CR and want to see what changed.
If you come from CR scripting, you might want to jump directly to #Proplists.

Script files

In OpenClonk one script-file usually belongs to an object or is in the global System.ocg directory.

Variables and Data types

OpenClonk does not use strict typing, you declare function-local variables with var, object local variales outside of functions with local and global variables with static. Such static variables might also be declared constant with static const.
Variables which have not been assigned any value yet, contain the value nil.
Parameters can have a type that is checked when the function is called.


Functions can be either declared global or without an access specifier which would make them object-local.
You can call functions from the same object like you would expect with FunctionName(parameters...). If you want to call a function in another object, use the arrow notation (my_object->MyFunctionCall(par1, par2, par3);).


Arrays in Clonk are declared with brackets (var a = []; or var a = [3];) and grow dynamically when a field is assigned a value for the first time. You can get the length of arrays with GetLength().
Indices start at 0.


Proplists are like assoziative arrays (if you come from another programming language, think of a map) and are declared with curly braces (var p = {}; or var p = { foo = 1, bar = 2 };).
You can access elements from a proplist with either the dot-notation p.key and p.key = value; or with the brackets and the key as a string (p["key"] = value;).
Note that in Clonk a lot of things are proplists: even objects! You can access the local variables of an object like any proplist elements.
Proplists can also contain functions, which are then called with the arrow notation as described above.

The next part of this tutorial about callbacks and timers is here.