Skip to main content

Variables and expressions

This part is for when a number needs to change along with the sheet. For most simple rules, Fixed mode and the visual builder are enough.

What does @forca mean?

A variable is a nickname for a sheet value. @forca reads Strength; @forca + 2 takes that value and adds 2. If Strength is 3, the result is 5. The @ tells the editor it is a variable.

Use the names the editor suggests. For names with spaces, wrap them in braces: @{Força Bruta}. Modifiers and maximums usually have their own names, such as @forca_mod and @vida_max.

A variable name that does not exist counts as 0. This is the most common cause of wrong results. Writing tips: use a dot for decimals (1.5), * to multiply (@forca * 2) and quotes around text ("fire").

@nivel + 2
floor((@forca - 10) / 2)
clamp(@vida + 5, 0, @vida_max)
@{Força Bruta} * 2

How to write a yes-or-no question

A condition is a question. @vida > 0 asks whether Health is above zero. @forca >= 3 asks whether Strength is 3 or more. > is greater than; >= is greater than or equal; < is less than; <= is less than or equal.

== asks whether two values are equal (two equal signs) and != asks whether they differ. and means both questions must be yes. or means one is enough. not flips the answer. Parentheses group things, as in arithmetic.

The If step chooses a whole path. If you only want to choose between two values inside a calculation, use if(question, value if yes, value if no). Text must match letter by letter: Fight and fight are different.

@forca >= 3 and @vida > 0
$event.attribute == "agilidade"
if(@nivel >= 5, 2, 1)
if(@vida <= 0, "Down", "Standing")

Advanced: $event, $sheet and another step's result

You only need this in rules that use roll data or an earlier step's result. $event reads what started the rule (for example, the roll). $sheet reads the whole sheet. $("Step name") reads the result of a step that already ran.

In a roll rule, $event offers formula, total, dice, skillName and attribute. What exists depends on the trigger: before the dice are rolled, total and dice do not exist yet.

$sheet holds attributes, skills, Health, Mana, fields, cards and the sheet's memory (memory). When something is a list, [0] picks the first item, [1] the second, and so on. When a value does not exist, it shows up as null, which means “empty”.

To use $("Step name"), copy the Step name exactly and do not reuse that name on another step. The step you read must have run earlier, on the same path. Ask returns the answer itself. Choose returns the chosen item, with information such as name, total and targets (that item's fields).

When a value may be empty, coalesce(value, 0) uses 0 in its place. Only empty values are replaced: a 0 or blank text stays as it is.

$("Roll dice").total
$("Ask")
$("Choose").targets.misc
$sheet.skills[0].name
coalesce($sheet.memory.usos, 0)

How to put a value inside text or a roll

In number or condition fields, write the calculation directly. In text or dice fields, in Expression mode, put only the calculated part between {{ and }}. For example: Total: {{ @forca + 2 }} shows Total: 5 when Strength is 3. In the Ask step's options, {{ }} calculates values in both modes. In Fixed mode, write one option per line, without quotes or brackets. In Expression mode, write a list of quoted texts, as in the example below: the list is evaluated first, then the {{ }} parts of each option. If @pm is 10, the options show 1 die - 10 MP and 2 dice - 20 MP. Options that become empty after evaluation are hidden.

To roll 1d20, use the Roll dice step: an expression on its own does not roll dice. Dice formulas can use sheet variables; the rolling guide explains options such as keeping the highest die and exploding dice.

Text in expression mode:
Total: {{ $("Roll dice").total }}

Dice in expression mode:
1d20 + {{ @forca_mod }}

Ask options in Fixed mode:
1 die - {{ @pm }} MP
2 dice - {{ @pm * 2 }} MP

Ask options in Expression mode:
["1 die - {{ @pm }} MP", "2 dice - {{ @pm * 2 }} MP"]

Condition in expression mode:
@vida > 0

Ready-made calculations (functions)

A function is a ready-made calculation you use in a formula. max(@dano - 2, 0) subtracts 2 from damage but never goes below 0. clamp(@vida + 5, 0, @vida_max) adds 5 to Health and keeps the result between 0 and the maximum.

min picks the lowest value and max the highest. floor rounds down, ceil rounds up and round rounds to the nearest.

For lists: sum adds, avg averages, len counts the items, first and last pick the first and last, and contains checks whether something is in the list. For text: upper and lower switch to upper or lower case.

There are other math functions, such as square root, power and trigonometry. You do not need them to get started; the expression guide inside the editor lists all of them.

max(@dano - 2, 0)
ceil(@nivel / 4)
round(2.5)
contains(["forca", "agilidade"], $event.attribute)
join($event.dice, " + ")