book-openAdvanced 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);
circle-info

Dynamic array methods use -> (e.g. list->append(x)). Fields use . (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 (inclusive ranges)

0..n-1 is common for “slot-style” loops:

circle-exclamation

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_reference/ folder containing the latest core API surface. If you’re trying to find “what methods exist on this type?”, that folder is the source of truth.

Last updated