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

Random, Math, & More

This page is a grab-bag of “you’ll use these constantly” utilities: RNG, formatting, time, and a few core subsystems that show up in most games.

If you’re looking for arrays/slices, see Arrays and Collections.

Random numbers (RNG)

Random uses an explicit u64 seed. Pass the seed by ref so it updates.

rng: u64 = rng_root_seed();
// or deterministic per-entity:
// rng: u64 = rng_seed(entity.id);

// Range values are inclusive
roll := rng_range_int(ref rng, 1, 10);
chance := rng_range_float(ref rng, 0, 1);

// Random points and shuffling
offset := rng_disk(ref rng, 0.5, 2.0);
spawn_points: [..]v2;
spawn_points.append({0, 0});
spawn_points.append({4, 0});
rng_shuffle(ref rng, spawn_points);

Math functions

Common math helpers:

String formatting

Use % placeholders with an argument array:

If you need an argument adjacent to a percent sign (or next to another argument), use %0 as an alias for %:

For decimal rounding, use format_float:

Common string helpers:

Logging

Logging follows the same formatting rules:

Time

SFX

Economy quick start (currencies)

Economy currencies are per-player and automatically persisted.

Deposit and withdrawal amounts must be non-negative.

See Economy for the full guide.

Last updated