Expression functions
Functions you can use in expressions for conditions and variables (such as @set game.x = randint(1, 6)) and inside {= …} in text.
| Usage | Description |
|---|---|
random()random(n) | With no argument, a number from 0 up to (but not including) 1. With n, an integer from 0 up to (but not including) n |
randint(a, b) | An integer from a to b, inclusive |
pick(array) | One element picked from the array (null if it's empty) |
shuffle(array) | A new array with the elements in random order |
floor(x) | Round down |
ceil(x) | Round up |
round(x)round(x, digits) | Round to the nearest integer. With digits, round to that many decimal places |
min(a, b, …) | The smallest number |
max(a, b, …) | The largest number |
abs(x) | Absolute value |
clamp(x, low, high) | Keep the value between low and high |
sum(array) | Sum of the numbers |
len(string or array) | Number of characters in a string, or length of an array |
includes(string or array, value) | Whether it contains the value |
index(string or array, value) | Position of the first occurrence of the value (-1 if not found) |
slice(string or array, start)slice(string or array, start, end) | Part of it (end is excluded; to the end if omitted; negative numbers count from the end) |
replace(string, search, replacement) | Replace every occurrence |
upper(string) | Convert letters to uppercase |
lower(string) | Convert letters to lowercase |
trim(string) | Remove leading and trailing whitespace |
split(string, separator) | Array of the parts divided by the separator |
join(array)join(array, separator) | String joined with the separator (empty if omitted) |
pad(value, digits)pad(value, digits, fill) | Pad the front to the given number of digits (with 0 if fill is omitted) |
str(value) | Convert to a string |
num(value) | Convert to a number (null if it can't be read as a number) |
push(array, value) | A new array with the value added at the end |
remove(array, value) | A new array without that value |
sort(array) | A new sorted array (numbers in ascending order, strings in dictionary order) |
reverse(array) | A new array in reverse order |
unique(array) | A new array without duplicates |
keys(object) | Array of the names |
has(object, name) | Whether the name exists |
version_before(version, "1.1.0") | Whether the version comes before the other one (1.9.0 is before 1.10.0, and 1.1.0-beta is before 1.1.0; an empty version comes before every version). Compare save.version with it when an update moves variables in old saves |
year() | The current year (from the player's device clock) |
month() | The current month (1 to 12) |
day() | Today's day of the month (1 to 31) |
hour() | The current hour (0 to 23) |
minute() | The current minute (0 to 59) |
weekday() | Today's day of the week (0 is Sunday, 6 is Saturday) |
now() | The current time (milliseconds since 1970) |
item("name") | How many of the item the player has (a name from items in liminalia.json; 0 if none) |
visits("#label")visits("file#label")visits("file") | How many times this playthrough has entered the label (or the start of the file if only a file is given). Counting starts at 1 inside the label, so it's 1 on the first visit. Saved with the game |
read("#label")read("file#label")read("file") | Whether the label (or the start of the file if only a file is given) has ever been entered in any playthrough (read status, shared by all saves) |
chosen("choice text") | Whether this playthrough has picked the choice with that text (write ruby as the base text; use the original text, not a translation). Saved with the game |
lang() | The language being played (one of languages in liminalia.json, such as ja or en) |
platform() | The kind of device: pc (computer) or mobile (phone or tablet) |
app() | Whether the game runs in an app (desktop or mobile version). false in a browser |
replaying() | Whether a replay from Extras is playing |
chapter() | Chapter of the current scenario file (an id from chapters in liminalia.json; empty if it belongs to no chapter) |
endings()endings("bad") | Number of endings seen in any playthrough (shared by all saves). Pass a kind (bad and so on) to count only that kind. Seeing the same ending again doesn't count twice. The current playthrough's ending counts once the command that ends the play (@title-screen) runs |