Getting Started with CSL
CSL is All Out's custom programming language built to make writing multiplayer games as easy as creating single player games.
CSL is All Out’s custom scripting language. It’s statically typed and feels most similar to Go/Odin — except gameplay state is automatically synced from the server to clients.
Your first script (main.csl)
When you create a new project, All Out generates a main.csl in your project’s scripts/ folder.
import "core:ao"
// ============================================================================
// Global lifecycle
// ============================================================================
ao_before_scene_load :: proc() {
// Register item definitions, currencies, etc.
// Runs after the empty Scene exists, before scene content is loaded.
}
ao_start :: proc() {
// Called once when the scene starts.
}
ao_update :: proc(dt: float) {
// Called every frame.
}
ao_late_update :: proc(dt: float) {
// Called every frame after ao_update.
}
ao_draw :: proc(dt: float) {
// Cosmetic-only. Interactive UI belongs in ao_update/ao_late_update.
}
// ============================================================================
// Player lifecycle
// ============================================================================
Player :: class : Player_Base {
ao_start :: method() {
}
ao_update :: method(dt: float) {
}
ao_late_update :: method(dt: float) {
}
ao_draw :: method(dt: float) {
// Cosmetic-only. Never interactive UI.
}
ao_end :: method() {
}
}For example, log a message when each player joins:
If you want a deeper explanation of when these functions run, see Game/Frame Lifecycle.
Imports
Your main.csl should import core:ao and any folders you create (like ui/, abilities/, etc).
Imports point at folders, not individual files. A folder import includes the .csl files in that folder. Imports inside that folder are resolved relative to it:
Declarations (variables and constants)
Declarations bind a name to a value.
Variables
Either <type> or <expression> can be omitted:
Constants
Constants use :: and must be compile-time constants. They can be scalars, strings, types, procedure values, arrays, or compound literals:
This is invalid (because a is not compile-time constant):
Global variable initializers must also be compile-time constants. Use ao_before_scene_load or ao_start for runtime initialization.
Global variables
Globals use the same declaration syntax as locals. They can be left zero-initialized or initialized with compile-time constants, including structs, arrays, procedure values, and typeid values:
Globals are mutable and persist for the lifetime of the script instance. They are synced game state like component fields: on clients, every server sync overwrites them with the server's values, so they cannot hold client-only state. A hotload keeps their current values, so an edited initializer applies only after a game restart; hotload does apply edits to :: constants, so declare read-only data tables as constants. Avoid using globals for per-player gameplay state.
Types
Primitive types
Signed integers:
s8,s16,s32,s64Unsigned integers:
u8,u16,u32,u64Booleans:
boolFloats:
f32,f64Aliases:
int==s64uint==u64float==f32
Vectors:
v2,v3,v4stringtypeidany
Numeric literals
Fractional literals can include or omit the zero before the decimal point. For example, .52 and -.52 are equivalent to 0.52 and -0.52:
Vector types
v2 has .x, .y; v3 adds .z; v4 adds .w — all float fields:
Structs and classes
Structs are value types (copies on assignment). Classes are reference types (you allocate them with new).
Structs (value types)
Classes (reference types)
Properties
A getter property keeps field-style read syntax without storing a field. Each read calls the named zero-argument method, and the method must return the property's declared type. Properties cannot be assigned or have an initializer.
Class fields can have default values. A derived class can override inherited defaults without redeclaring the field:
Inheritance
Structs/classes can inherit from other structs/classes:
Derived methods with the same name shadow inherited methods. Calls are not virtual: method lookup uses the receiver's static type, so calling through a base-typed value never selects a same-named method from the derived type.
Derived classes expose a read-only base field that views the same object as its immediate parent type. It lets method lookup start from the parent type explicitly:
base is not a reserved word. A local declaration named base shadows the inherited field normally.
Procedures and methods
Procedures (proc)
Procedures returning multiple values must wrap the return types in parentheses:
Use the same comma-separated form with = to assign results to existing destinations. An assignment can consume either one multi-return expression or one expression per destination:
The number of destinations must match the number of values. Right-hand expressions are evaluated from left to right before any destination is resolved or written. This makes swaps safe, and _ can ignore a value:
Comma-separated right-hand expressions are supported specifically by assignment statements; they do not create a tuple value that can be used in another expression.
Procedures are normal values and can be assigned/stored like any other value:
Every procedure needs a unique identity so hotloading can match old and new code. Named declarations (add :: proc(...)) get this automatically. A :=/= proc value stays anonymous — one anonymous proc per scope is fine, but if a scope holds more than one, give each a unique link name with proc "name" (...) or the compiler reports a link ID collision.
Methods (method)
Use method() inside a struct/class. Methods have an implicit this reference parameter.
Use method #read_only_this (...) for a read-only receiver:
For a struct, this supplies using this: ref Particle_Emission #read_only. The method can be called on a #read_only field, but cannot modify its struct receiver or pass it to a method requiring a mutable receiver.
Field access vs method calls
Use . for both fields and methods:
Arrays
CSL has a few “array-like” types you’ll use constantly:
Fixed arrays:
[4]intSlices / managed arrays:
[]T(often used as “read-only view” into an array)Dynamic arrays:
[..]T(resizable list)Unmanaged arrays:
[^]T(used in built-in API signatures likeformat_string,log_info, etc — pass values as{a, b, c})
Dynamic arrays can be initialized with a compound literal. They expose .count and .capacity, and use method-call syntax for operations:
For a full guide (including removal patterns), see Arrays and Collections.
Control flow
If / else
Switch
Use default: for the default clause. Cases support multiple values (comma-separated) and ranges. No C-style fallthrough.
.. includes both endpoints. ..< excludes the upper endpoint.
While / for
Custom iterator-based for loops require a next :: method() -> bool and a current field.
Casting
Use expr.(T) or cast(T)expr to cast:
When the target type is already known, you can let CSL infer it:
Procedure values cannot be cast to another procedure signature or to/from non-procedure values.
Class casts must stay within one inheritance hierarchy. Upcasts do no runtime work; downcasts verify the concrete object type and throw on a mismatch. Null class values remain null when downcast.
Passing by reference: ref
Use ref when a procedure needs to modify the caller's value:
A reference parameter marked #read_only can receive a read-only field. It can read the value, but cannot modify it or pass it to a mutable reference parameter:
For reference parameters, #read_only is part of the procedure signature and is preserved through callbacks and reflected procedure lookup. A procedure taking a mutable reference cannot be assigned to a callback promising #read_only. For classes and managed arrays, #read_only prevents replacing the value; their contents remain mutable.
Closures and callbacks
Procedure literals can capture enclosing parameters and local variables:
Capturing procedure literals are scoped callback expressions. They may only be invoked immediately or passed directly to a procedure parameter that accepts captures. That parameter may invoke the callback or forward it directly to another capture-accepting parameter. Capturing procedures cannot be assigned to variables, returned, or placed in fields, globals, collections, or other storage.
An unannotated procedure parameter might receive a capturing procedure, so it has the same invoke-or-forward restriction. Mark the parameter #no_captures when the procedure needs to store, return, or otherwise manipulate it. Callers may then pass only non-capturing procedures; keep persistent state in explicit userdata:
The annotation is part of the receiving procedure's contract and may also appear in a procedure type, such as Retainer :: proc(userdata: Object, #no_captures callback: Callback).
Type info (types as values)
typeid values can be passed to polymorphic procs:
#type_info(T) returns reflection data for a type. Use its id field when logging or formatting the type's name:
Best practices (CSL in All Out)
Avoid global gameplay state. Multiple players connect — store per-player state on
Playerinstead.Draw all player UI from
Player.ao_late_update. Wrap it inis_local_or_server().Use
is_local()only for player-specific visual overrides. Do not change gameplay or UI state inside it.Mobile-first defaults. Don’t rely on keyboard/mouse input unless your game is explicitly PC-focused.
If you’re unsure about syntax or APIs, open the matching
.csl_enginefile underapi_references/in your project.
Last updated