For the complete documentation index, see llms.txt. This page is also available as Markdown.

Advanced Language Reference

CSL gives you a few “array-like” tools that cover most gameplay needs: fixed arrays, slices, and dynamic arrays. This page is the practical guide to using them without foot-guns.

Quick glossary

  • Fixed array: [N]T — size is known at compile time.

  • Slice / managed array: []T — a view over array data (often used for parameters).

  • Dynamic array: [..]T — resizable list with count and capacity.

fixed: [4]int = {1, 2, 3, 4};
view: []int = fixed; // slice view

list: [..]int;
list.append(10);
list.append(20);

Dynamic array methods use normal dot calls (e.g. list.append(x)). Fields also use dot access (e.g. list.count).

Dynamic arrays ([..]T)

Dynamic arrays are the “default list” type for gameplay code.

Creating and appending

players_seen: [..]string;
players_seen.append(player.get_user_id());

Reserving capacity (performance)

If you know you’ll add a lot of items, reserve first to avoid repeated reallocations.

Removing items

You generally pick between fast removal (order doesn’t matter) and ordered removal (preserve order).

You can also remove by index:

Clearing

Passing arrays into procedures

Many APIs accept []T (a slice/view). Dynamic arrays can be passed where []T is expected.

Iteration patterns

Iterate elements

Iterate indices

Use ..< when you want a normal "0 up to, but not including, count" loop:

Reverse loops use #reverse:

Hashtables

Use Hashtable(Key_Type, Value_Type) when you need fast lookup by key. It supports integer and string keys, along with the usual methods for lookup, insertion, overwrite, removal, and iteration.

Use add when duplicate keys should assert. Use add_or_overwrite when updating an existing key is expected. try_add returns true if the key already existed and leaves the old value unchanged.

Closures, callbacks, and userdata (important)

CSL does not have closures. Inline proc() { ... } definitions cannot capture surrounding variables.

When you need callbacks (UI handlers, death hooks, etc), pair the callback with a userdata: Object field.

API reference

Each project includes an api_references/ folder containing the current core API. Open the matching .csl_engine file to inspect a type or procedure.

Last updated