Vǫrðr Forge Steam page

Rûn Language

Rûn Rule Blocks

A rule block lets a program step into one of the engine's own events as it happens: before a hit lands, before an item is picked up, after a level is gained. It is how a game changes its rules without changing the engine.

before and after

A rule block is written at the top level of any program in assets/scripts, never inside a section or a function:

before <event>(<type> <name>, ...) { ... }
after <event>(<type> <name>, ...) { ... }
before
Runs before the engine acts. It may change the values the event lets it change, and it may stop the event with refuse("why") (the player sees the words) or return false.
after
Runs once the thing has happened. It changes nothing.

Every program that has a block for an event runs it, in the order the files are read. The engine reads which programs answer which events when the project opens, when a script is saved, and when a test starts.

Parameters bind by name

An event hands over a set of named values. A block asks only for the ones it needs, by their names, in any order, and each with the type the event gives it: a number, text or toggle. Asking for a name the event does not hand over, or with another type, is an error that lists what the event does hand over.

// spark hits hurt twice as much; nothing hurts the shrine keeper
before damage(number amount, text target, text by) {
    if (by == "spark") amount = amount * 2
    if (target == "shrine_keeper") refuse("The keeper is beyond harm.")
}
after levelup(number level) {
    print("now level", level)
}

Setting a parameter in a before block changes that value for the engine, if the event marks it changeable. The events and their values are listed under Before and after on Rûn Programs; the changeable values are in bold there.

Seeing one work

A before pickup block hears every item that goes into her pockets, give and Player.Give included, so it can be tried in Test mode from the console. Make an item to refuse, and one to let through:

itemdef rule_idol Cursed_Idol
itemdef rule_charm Lucky_Charm
savedata items
before pickup(text item, number count) {
    if (item == "rule_idol") refuse("It burns to the touch.")
}
Player.Give("rule_charm", 1)
Player.Give("rule_idol", 1)
print(Player.Count("rule_charm"), Player.Count("rule_idol"))
1 0

The charm went into her pockets; the block refused the idol, so she carries none. Dice rolled with a program's roll() do not raise the roll event; the d20 fight's own rolls do.

Damage and the d20 rules

before damage hears every hit: her attack, a foe's, a spell's and World.Hit. Its values are amount (changeable), target, source, by and type.

The d20 fight raises roll, encounter, round, turn, move, reaction, area and target. A before roll block may change advantage, disadvantage, natural and total, and add a named modifier with addmodifier("blessed", 2); modifiers() lists what the engine's own steps added. The fight's numbers (action points, reach, cover, flanking, critical hits) are rows of assets/data/rules.vfa; a program reads one with rule("crit") and changes it for the session with setrule("crit", "19").

print(rule("crit"), rule("flanking"))
20 off

See Combat for the fight itself.

What a rule block may not do

A rule block has to answer at once, inside the engine's own step. Methods that play out over time are refused inside it: World.Fire, the camera's moves. Raise a flag in the block, and let an event or a live program act on it.

refuse() belongs only in a before block. Outside one it is an error.