Library
Numbers
| Function | |
|---|---|
min(a, b), max(a, b) | |
clamp(x, lo, hi) | lo > hi is an error |
abs(x) | |
floor(x), ceil(x), round(x) | round rounds halves away from zero; a result that does not fit an int is an error |
sqrt(x) | |
mod(a, b) | 0 … b-1 for b > 0: mod(-7, 3) == 2; b ≤ 0 is an error |
Strings
| Function | |
|---|---|
length(s) | in code points |
contains(s, part) | |
slice(s, from, to) | in code points |
Time
| Function | |
|---|---|
now() | the world's minute (int) |
clock() | the time of day (time) |
hour(t), minute(t) | |
t.between(a, b) | whether t is in [a, b); may pass midnight (22:00–06:00); a == b is always false |
Colours
Colour channels are on a 0–1 scale; c.r, c.g, c.b, c.a read them.
| Function | |
|---|---|
rgb(r, g, b), rgba(r, g, b, a) | rgb(1, 0.5, 0) is orange |
mix(a, b, t) | a + (b − a) × t on all four channels |
scaled(c, f) | RGB × f |
multiply(a, b) | RGB channel by channel; the alpha is a's |
withAlpha(c, a) |
Server only
| Function | |
|---|---|
random() | a float in [0, 1) |
random(a, b) | an int from a to b, both included; a > b is an error |
log(...) | writes to Play's log (log) |
Client only
sin(x), cos(x) and pi. They give the same result on every platform.
Caria's calendar
Caria's year has 12 months of 28 days: four weeks a month, and every month's 1st is a Monday, so
the day of the month decides the day of the week. A year is 336 days, with no leap years and no
29th–31st; years count from 1. A world starts at a date and a time (its .world document's
start), and the date is computed from the world's minute. The calendar is the game's, not the
language's; the server gives it as functions that read the world's clock.
| Function | |
|---|---|
year() | the game year, from 1 |
month() | 1 January … 12 December |
day() | the day of the month, 1–28 |
weekday() | 1 Monday … 7 Sunday |
season() | "spring" (March–May), "summer" (June–August), "autumn" (September–November), "winter" (December–February) |
There is no list of holidays: a holiday differs by building and by person, and each checks the
date in its own script (month() == 10 and day() == 28).
on timer cut
// No maintenance cut on Sundays or in summer.
if weekday() != 7 and season() != "summer"
power.on = false
end
end
Effects
Every function has an effect; the compiler follows it through calls.
| Effect | Meaning | Examples |
|---|---|---|
pure | depends only on its arguments | numbers, strings, colours, between; sin cos pi on the client |
read | reads the world or the clock | now clock, the calendar |
transactional | writes to the transaction's record; undone with it | random |
diagnostic | changes no behaviour and is not undone | log |
- A client
applymay call onlypurefunctions. enterandexitcannot reachgoto.- A function never hands back a live object of the game, only values; the world changes only
through the transaction and the script's
writes. - An expected outcome of the game ("no route") is a return value, not an error.