# 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
id
definition id
ID of an object definition (see Object Definitions).Will be changed into a proplist immediately.
Clonk
string
String
Any text.
"Dies ist ein 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 }
object
Ingame Object
Reference to an existing object at runtime. No direct representation. See FindObject()
CreateObject(Clonk)
any
The type of `nil`. When used as a function parameter type, the type check is skipped.
nil

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. If an array is stored in a variable or used as a parameter to a function, the new variable has it's own copy of the array. The actual copy is deferred if possible, though. If an array is passed to a function for modification, a reference has to be used.
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, HUT1]; return (a[Random(4)]); }
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.
Proplists
Proplists can be created with `{key 1=expression 1, key 1=expression 1, ...}` or with CreateProplist.
Conversion
Consult the following table to determine which types can be converted and which conversions might cause errors:

to ->
int
bool
object
string
array
proplist
int
OK
OK
if 0
if 0
if 0
if 0
bool
OK
OK
Error
Error
Error
Error
object
Error
OK
OK
Error
Error
OK
string
Error
OK
Error
OK
Error
Error
array
Error
OK
Error
Error
OK
Error
proplist
Error
OK
maybe
Error
Error
OK

Additional information:

- Conversion to bool is generally allowed. All values except 0 are `true`.
- If an object has been converted into a proplist then it can be converted back to an object. Otherwise proplists cannot be converted into objects.
- `0` can be converted into anything. In that case it behaves the same way as `any`

Günther
2010-03
PeterW
2006-04