Formulas and functions
The full catalog of the formula engine functions, with signature, syntax and examples, generated from the engine itself.
Every Roliando formula (derived fields, limits, effects, thresholds and bonuses of a roll, conditions of a decision, creation steps) is evaluated by the same engine: an interpreter with a whitelist of functions that never runs code. This page is the complete catalog, generated from the engine itself, to look things up while you write. How fields are built and where each formula is written is in Fields and formulas.
Where they are used
A formula is written in the system builder (Functions lets you name the ones you repeat), in derived fields, in limits, in effects and in rolls: the threshold, the bonus, how many dice are rolled and the condition of a later decision. While you type, the editor suggests the fields and functions that match, warns underneath when something is not understood or names a field that does not exist and shows the result with sample values.
Syntax
- Numbers and texts in quotes:
'light'or"light". - Operators:
+ - * / %and parentheses. - Comparators:
< <= > >= == !=. If either side is not a number,==and!=compare as text. - Logic:
AND/OR/NOT, or&&,||and!. - Ternary:
condition ? ifTrue : ifFalse. - References: the name or key of any field. A field that does not exist is worth 0 and does not break the sheet.
field_value: in roll thresholds, the value of the field itself.
Functions
Each table groups the functions by what they do. The first column is the signature as it is written; arguments go in parentheses separated by commas.
Logic and conditions
| Function | What it does |
|---|---|
IF(condición, siVerdadero, siFalso) | One value or another depending on the condition. Example: IF(vigor > 50, 2, 1). |
IFS(cond1, val1, cond2, val2, …, porDefecto) | Several conditions in a chain: the first value whose condition holds; the last loose value is the default. Example: IFS(life <= 0, 0, life < 5, 1, 2). |
AND(a, b, …) | True if every condition holds. |
OR(a, b, …) | True if any condition holds. |
NOT(a) | Inverts a condition. |
XOR(a, b, …) | True if exactly ONE of the conditions holds. |
BETWEEN(x, min, max) | True if x is between min and max (both included). Example: BETWEEN(level, 5, 10). |
Numbers
| Function | What it does |
|---|---|
MIN(a, b, …) | The smallest of the values. |
MAX(a, b, …) | The largest of the values. |
FLOOR(x) | Rounds down. |
CEIL(x) | Rounds up. |
ROUND(x) | Rounds to the nearest whole number. |
ABS(x) | Absolute value (without sign). |
CLAMP(x, min, max) | Keeps x between min and max. Example: CLAMP(hp, 0, hp_max). |
SUM(a, b, …) | Adds all the values (a list works too). Example: SUM(LOOKUP('creatures', species, 'moves.[].power')). |
AVG(a, b, …) | Average of the values (a list works too). |
POW(base, exponente) | Power. Example: POW(2, level). |
SQRT(x) | Square root. |
MROUND(x, múltiplo) | Rounds to the nearest multiple. Example: MROUND(weight, 5). |
Lists
| Function | What it does |
|---|---|
COUNT(lista) | How many items a list has. Example: COUNT(LOOKUP('creatures', species, 'moves')). |
INCLUDES(lista, valor) | 1 if the list contains that value (ignoring case and accents). |
INDEX(lista, n) | Item n of a list, counting from 1. Example: INDEX(types, 2). |
JOIN(lista, separador) | Joins a list into one text. Example: JOIN(LOOKUP('creatures', species, 'moves.[].name'), ' / '). |
FILTER(lista, campo, valor) | The list items whose field has that value. Example: COUNT(FILTER(LOOKUP('creatures', species, 'moves'), 'type', 'Fire')). |
Text
| Function | What it does |
|---|---|
CONCAT(a, b, …) | Joins texts. Example: CONCAT(name, ' the ', nickname). |
LEN(texto o lista) | Length of a text, or how many items a list has. |
CONTAINS(texto, trozo) | 1 if the text contains that piece (ignoring case and accents). Example: CONTAINS(class, 'mage'). |
UPPER(texto) | Text in capitals. |
LOWER(texto) | Text in lowercase. |
TEXT(x, decimales) | A number as text with that many decimals. Example: TEXT(weight / 3, 1). |
SIGNED(x) | A number with its sign: "+3", "-2", "0". For showing modifiers. |
System databases
| Function | What it does |
|---|---|
LOOKUP(catálogo, nombre, campo) | Value of a field of an entry in a database of the system, found by name. Inside a list use 'moves.0.name' (one) or 'moves.[].name' (all of them). A link to another database can be followed by nesting. |
CATALOG_COUNT(catálogo) | How many entries a database has. Example: CATALOG_COUNT('creatures'). |
CATALOG_SUM(catálogo, campo) | Sum of one field across ALL the entries of a database. Example: CATALOG_SUM('items', 'weight'). |
Perks and other fields
| Function | What it does |
|---|---|
HAS_PERK('clave', …) | 1 if the character has any of those perks (by key), 0 if not. It also counts the ones the GM gives and passive ones. |
COUNT_PERKS('categoría') | How many perks of that category the character has (the category or those starting with it). |
CAMPO(nombre) | Value of the field with that name (by visible name or key). Example: CAMPO(attribute) gives the value of the attribute chosen in a selector. |
Examples
Classic modifier: FLOOR((might - 10) / 2). Hit points per level: stamina + level * 2. Never below 0 nor above the maximum: CLAMP(life, 0, life_max). Depends on the class: IF(class == 'mage', 3, 1). Step by level: IFS(level >= 10, 4, level >= 5, 2, 1). With a function of your own: BONUS(might) + 2.
Common mistakes
"It gives 0 and I do not know why." The field name does not exist or is misspelled: an unknown field is worth 0. Look at the warning under the formula.
"A text comparison is never true." Texts go in single or double quotes; class == mage looks for a field called "mage".
"LOOKUP gives 0." The system has no such database, or the entry name matches nothing. Databases are explained in Fields and formulas.
See also
Fields and formulas, Rolls, System Builder: first steps, Chat commands and dice.