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 withcountandcapacity.
fixed: [4]int = {1, 2, 3, 4};
view: []int = fixed; // slice view
list: [..]int = {10, 20};Dynamic arrays ([..]T)
Dynamic arrays are the “default list” type for gameplay code.
Creating and appending
players_seen: [..]string = {"Ada", "Grace"};
players_seen.append(player.get_user_id());Dynamic-array literals may contain runtime expressions and can be returned directly when the expected type is [..]T:
Dynamic-array class field defaults are also supported. Each class instance receives independent mutable storage:
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:
Some engine collections provide iterators. inventory.slots() visits every slot in order, yields null for empty slots, and exposes the actual slot as the optional index:
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 and callbacks
Procedure literals may capture surrounding values, but capturing procedures are callback expressions and cannot be stored in collections or other locations. A procedure parameter must be marked #no_captures before it can be stored, and callers may then pass only non-capturing procedures; see Closures and callbacks for the usage rules and explicit-userdata pattern.
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