Graphs
Functions and library mods
A function is a graph made into a node: it takes inputs, does its part, and gives outputs back. Pay the toll takes who pays and how much, and says whether they paid. Once made, it is used like any node, in every graph of the mod and of the mods that require it.
In a file
A graph file holds its functions under "functions", beside its own nodes or instead of them:
"functions": [ {
"name": "PayToll", "title": "Pay the toll", "note": "Takes the price from who's purse.", "category": "Roads", "pure": false,
"inputs": [ { "name": "who", "kind": "Object", "type": "Player.Character" }, { "name": "price", "kind": "Int", "value": 2 } ],
"outputs": [ { "name": "paid", "kind": "Bool" } ],
"vars": [ ... ], "nodes": [ ... ], "wires": [ ... ]
} ]- Inside a function, Start (
fn/in) is where it begins: its outputs are the function's inputs, andthenunless the function is pure. - Return (
fn/out) ends it: its inputs are the function's outputs, andinunless pure. A function may return from several places. - A pure function ("Runs: when asked") has no run pins. It is worked out when a node asks for its value, like a maths node, and has one Return.
- Each function is a node kind,
fn/<mod id>.<Name>, listed under its mod's title and its category.
Making one on the bench
- Each graph has a Functions list in the side panel when nothing is picked. + makes one: name it, then add its inputs and outputs, each a name and a kind from a drop-down (and a type for things and lists).
- Make a function (the node menu, or the side panel with several picked) turns the picked nodes into one, rewired: wires coming in become inputs, wires going out outputs, and a call is put where the nodes were.
- Double-click a function's node to open it. A breadcrumb shows where you are; a click on it, or Esc, goes back.
- Inputs and outputs are made on the Start and Return nodes too: + Add pin, a name double-clicked to rename it in place, or a wire dropped on Start or Return making a new input or output of its kind. Up and down in the side panel reorder them.
- Renaming or removing an input or output follows every call of the function, in every graph of the mod.


Running
- Each call has its own variables, fresh every time, and counts against the run's 10,000 steps.
- Calls nest at most 64 deep, a function calling itself included.
- A Wait inside a function holds the whole run that called it.
- Events can't be put inside a function.
The game's library
The game ships about eighty functions of its own, open to every mod: fn/game.<Name>, under Library in the node list. Each is a small graph of book nodes, checked in the game as it is built. They open read-only; Copy into my mod puts a copy in your graph to change.

- People
9 functionsFinding people near a place, of a side, the nearest player. - Orders
13 functionsWalk, go home, follow or guard for a while; a whole band set on somebody, sent, guarding, fleeing, calmed. - Gear
5 functionsArming, disarming and dressing one person or a band. - Fighting
7 functionsFire for a while, harm and healing round a place. - Places
11 functionsRandom points, things spawned round a place, waiting for somebody to come. - Items
4 functionsGiving, taking and checking items. - Money
5 functionsPaying, buying and selling in coin. - Time
8 functionsNight and day, hours, the day of the week. - Weather
4 functionsTurning and holding the weather, lightning. - Story
7 functionsQuests once, rewards, flags as marks and counters. - Screen
2 functionsNotes to players. - Sounds
1 functionsSounds where somebody is. - Lists
6 functionsShuffle, pick, sum, average, biggest, smallest. - Maths
3 functionsBetween, percent, dice.
Every one has a page under Library, with its body drawn and the nodes it is built from.
Library mods
A mod made only of functions is a library other mods build on.
- A mod's graphs can use its own functions and those of the mods it requires, directly or through another mod that requires them. Other mods don't see them, even when switched on.
- The node list shows the mod's own functions under This mod, and its requirements' under Required mods, each under its mod's title.
- A required mod's functions open read-only, as the library's do, with Copy into my mod.
Examples/library (Roads and the watch) holds Pay the toll, Nearest guard to and Is it night. Examples/uses-library requires it and calls all three: every hour after dark, each player near a man of the watch pays two denars, and is told how it went.

Modding