# Data Types

Data Types
C4Script supports the following data types for variables, parameters, and return values:

Type Name
Full Name
Contents of Variable
Example
int
Integer
A whole number from -2.147.483.648 to +2.147.483.647.
42
bool
Boolean
"true" (value `true`) or "false" (value `false`). Expected as parameter by many structures such as if and while.
true
string
String
Any text.
"This is a text!"
array
Array
A type containing multiple variables, whose number can be enquired with GetLength, and which can be recalled with `array[index]`.
[0,23,Clonk]
proplist
Object
A general purpose object type. GetProperty and SetProperty can get respectively set properties. If the property `"Prototype"` is set, and a property that is not set is gotten, the prototype is asked.
{ foo = 0, "bar baz" = 13, Prototype = Clonk }
func
Function
A function. At the moment, this is only used to store them in proplists.
Flint.Hit
nil
The type of `nil`.
nil
any
When used as a function parameter type, the type check is skipped.
def
Object Definition
Represents a DefCore.txt and the associated Script.c. A special kind of proplist.
Clonk
object
Ingame Object
An instance of an Object Definition. A special kind of proplist.
CreateObject
(Clonk)
effect
Effect
A special kind of proplist with associated timers and stacking callbacks.
AddEffect
("Shiny", nil, 1)

Arrays
Arrays can be created directly with `[expression 1, expression 2, ...]` or indirectly with CreateArray(). They are automatically enlarged if necessary on element access, but it's faster to create them with the needed length from the start. Arrays behave like objects, you can only store references of them. Example: `var a = CreateArray(), b = a; b[0] = 42; // a is now [42]` A copy of `a` can be obtained with `a[:]`, as explained below.
Access to element `i` of array `a` is achieved through `a[i]`. `i=0` is the first element. Negative indices are counted from the end of the array, so that `a[-1]` refers to the last element of the array.
A range within an array can be copied with `a[i:j]`. The resulting array contains all elements with indices in the half-open interval `[i,j)`. Negative indices are treated as when accessing single elements. Both indices are optional and assumed as `0` and `GetLength(a)` respectively if not given.
Example 1
func ArraySum(array a) { var l = GetLength(a); var result = 0; for (var i = 0; i < l; ++i) { result += a[i]; } return (result); }
This function adds up all elements of an array.
Example 2
func RandomID() { var a = [Clonk, Wipf, Bird]; return (a[Random(3)]); }
This function randomly chooses one out of four ids and returns it.
Example 3
func DetonateNearest() { var a = FindObjects(Find_ID(Dynamite), Sort_Distance()); for (var dyna in a[:6]) { dyna->DoExplode(); } }
This function calls `DoExplode()` on the six nearest Dynamite objects.
An array may not exceed 1000000 elements. "ye shalt not create arrays larger than that!"
Proplists
Proplists are a datatype that maps values to strings and supports prototype inheritance.
Proplists can be created with `{key 1=expression 1, key 2=expression 2, ...}` or with CreateProplist.
Conversion

- All values except for `false`, `nil` and `0` are treated as `true` when a bool is required.
- `nil` and `false` can be converted to `0`. `true` can be converted to `1`.
- `nil` can always be used as a function parameter, if the function doesn't implement a separate check.
- Objects, Definitions and Effects can be converted to proplists, and then back. Normal proplists cannot be converted into them.

Günther
2010-2011
PeterW
2006-04