Data Editor Docs
How the data editor works, and a full reference for the expression language.
The data format, the data checker and the expression language are defined in the data validator repository: Force-Organization-Army-Builder/fo_data_validator. It holds the schema, the authoring guide, the specs, the fo-validate command and example sources: the full example a new install loads, which uses every part of the data format, and a minimal starter to copy from.
Writing data as JSON
The Data Editor is one way to make data. The other is writing the JSON files yourself, or having a coding agent such as Claude Code write them, then checking them with a command. Everything on this page applies to the files either way: the editor just writes the same JSON.
Start from the game template
For a new game in its own repository, the quickest start is the fo_game_template repository, a GitHub template set up for writing data with an agent or in your editor. It holds placeholder data that passes the check from the start, the validator pinned as a dependency (npm run validate), the GitHub check on every push and pull request, $schema lines for completion and inline errors in your editor, formatting settings, contribution and review docs, and a checklist for what to change after creating your copy.
On GitHub, open the template and click Use this template → Create a new repository (make it public so the app can load it), or use the GitHub CLI:
gh repo create <owner>/<new-repo> --template Force-Organization-Army-Builder/fo_game_template --public --clone cd <new-repo> npm ci npm run validate # 0 errors: the placeholder data is valid
Then work through its docs/after-creating-from-the-template.md: rename the game, replace the placeholder data and re-apply the GitHub settings a template doesn't copy (branch protection, Actions, Dependabot).
Without the template, install the validator anywhere and copy its starter source:
npm install git+https://github.com/Force-Organization-Army-Builder/fo_data_validator.git#v2.0.0 npx fo-validate node_modules/@force-org/data-validator/examples/starter npx fo-validate /path/to/my-data # your own folder, anywhere npx fo-validate /path/to/base /path/to/ext # an extension source: base first npx fo-validate /path/to/my-data --json # machine-readable issues
The validator lives in its own repository (fo_data_validator) and is the same code the app uses. The command checks each file's shape against the schema (wrong types, misspelt keys, missing fields) and then the same data checker the app uses (ids, references, stats and every expression). Errors name the file and the JSON path, underline the bad part of an expression and suggest the fix. It exits with 1 when there are errors, so it also works in CI.
Every id, record key and @selector reference is lowercase kebab-case (infantry-squad: letters a-z and digits, single hyphens between words), and a term's word also starts with a letter; anything else is a shape error, reported as invalid key 'Bad ID' for a key.
The manifest's versions are checked first, on the raw file: a source declaring a newer schemaVersion, expressionVersion or minValidatorVersion than the validator (or the app) knows is refused with one “update” error, and nothing else is read. Set "minValidatorVersion": "1.14.0" (exactly major.minor.patch) once your source uses a feature from that release or later, to the release that added it. Leave it out otherwise: validators 1.13 and older don't know the field and refuse it as an unknown property.
Give your agent these, which are plain text and need no browser:
/agent-docs/data_authoring_guide.md: Start here: the validate loop, source layout, every record type, expressions and common mistakes./agent-docs/schema/game.schema.json: The exact shape of a game definition (roles, resources, stat templates, shared groups, ...), with a description on every field./agent-docs/schema/faction.schema.json: The exact shape of a faction (units, gear, upgrades, rules, groups), with a description on every field./agent-docs/schema/sub-faction.schema.json: The exact shape of a sub-faction (records merged over its parent, unit modifiers), with a description on every field./agent-docs/schema/source-manifest.schema.json: The exact shape of a source manifest, with a description on every field./agent-docs/expression_language_spec.md: Syntax, types, scopes, functions and references for expression fields./agent-docs/data_schema_spec.md: The reasoning behind the schema (written before implementation: the JSON Schema and the validator win where they differ)./llms.txt: the site index for agents, which links all of the above and the starter source.
To try the result in the app, push the folder to a public GitHub repository and add it under Settings → Data sources (a branch works as the version), or import a single faction file with New Faction → Import from JSON.
How the data is organised
Everything the list builder knows comes from data, and there are no game rules in the code. The editor works with three kinds of record:
| Kind | What it holds | Edited on |
|---|---|---|
| Game | The rules framework: roles, unit types, group types, slot tags, resources, stat lines, list choices and list rules, plus the groups, special rules, slot options, named selectors and sub-choices every faction shares. | Game page |
| Faction | Units, weapons, equipment, upgrades, special rules and groups for one faction, plus its own selectors, slot options and sub-choices. | Factions page |
| Sub-faction | A modifier of one faction (a legion, a chapter, a regiment). Its records merge over its parent’s, and its unit modifiers add upgrades, change stats or make units unavailable. | Factions page, “Sub-factions” view |
The app works with one game at a time, picked in the nav. The editor shows only that game's data, and New Faction makes a faction for it. Ids are readable slugs (tactical-squad) and each record's id must match its key.
An id is lowercase kebab-case: letters a-z and digits, with single hyphens between words (infantry-squad, not Infantry_Squad). The editor makes new records' ids from their names this way, and an id you type (a game, roles, stats, list choice values, list rules and the other definition entries) shows the rule as you type and goes back to the old id if it breaks it. A term's expression word follows the same rule and must start with a letter. A faction file imported with Import from JSON is checked the same way and refused if any id breaks the rule.
Drafts, versions and sharing
- Each editor page holds one draft over the version you loaded. Every edit goes straight into the draft; individual records have no Save or Reset of their own.
- A dot on a record's header means it differs from the saved copy. Its
⋯menu can Revert or Delete it. - The unsaved changes bar lists what has changed, discards the draft (with undo) and warns before you leave the page.
- Save Version is the only save. It stores a numbered copy in this browser's local storage. The dialog can also switch the list builder to the new version.
- Choose which saved version the app uses in Settings → data versions. The data source's data is the fallback, and it is never overwritten.
- Download writes the data exactly as edited. On the Game page, Download Source zips the game with its factions and sub-factions as a data source folder you can share. Its
forceorg.jsonkeeps theminValidatorVersionof the source the game came from, if it had one; the app never adds one, since validators before 1.14.0 refuse the field.
Saved army lists keep a copy of the restrictions they were built with and are stamped with the data versions they used. When you change data, lists built on older versions are flagged rather than silently changed.
The Game page
The Game page edits game.json in one record browser like the Factions page (search, Changed and Has issues filters, Ctrl K). Its rail has three parts: Game (Identity & Terms, a single form, and List Rules), Definition (roles, unit types, slot tags, resources, stat lines, list choices and group types) and Records (shared groups, slot options, universal rules, named selectors and sub-choices). Everything stays mounted, so a role you add is available to the groups straight away. The + button asks which kind of list rule, or which group type of group, to add. Every entry and record has a Used by list: a role, resource, stat line or other definition entry lists the records that would break without it (found by the data checker, so expressions count too), and a universal rule, selector or sub-choice lists the records that point at it. Records in the game open beside the list; faction and sub-faction records link to the Factions page. The data checker runs over the game with every faction written for it as you edit, and marks each entry or record with problems; anything that belongs to no entry shows on Identity & Terms. Renaming an id or deleting an entry other data uses asks first, listing what it would break. Use New Game to start an empty game or a copy of another; Delete Game removes a custom one.
| Rail entry | What you set |
|---|---|
| Identity & Terms, Definition, List Rules | Identity and terms (the game’s words for groups, root groups and so on), roles (and what they grant), unit types and sub-types (each with a description: its rules, which players open from the unit’s type and from a unit or profile tag naming the sub-type by name or id, e.g. Heavy), traits (the game’s list of unit traits, each with a description players open from the trait on the unit; once a game lists its traits, a trait the data uses that isn’t listed is a warning), slot tags, resources, unit and weapon stat lines, list choices (each value can carry stat, special-rule and trait effects that every unit in the list takes while the value is picked, limited to the units a selector matches), group types (root or linked, faction source, min/max, cost) and list rules. A slot tag can take a colour and an icon from the app’s fixed lists; the list builder marks the tag’s slots with them, and picks a look from the tag’s id when none is set. |
| Groups | Shared groups by group type: their slots, which roles each accepts, and their restrictions. Slots are grouped in rows by the roles they take; each row ends with a button that adds another of its slots, and Add Slot picks the role for a new row, or adds one slot of each role ticked under Several slots…. A slot any of several roles can fill gets its roles in its settings. Named for the game’s group word. |
| Slot Options | Choices that a slot with a tag offers, one per tag (HH prime benefits): rules text, an optional cost, and effects on profiles. An Extra group slot effect adds slots to the group: Slots added sets how many, each taking its own unit, all of the one role the player picks. Shown once the game has slot tags. |
| Universal Rules | Special rules every faction shares. |
| Named Selectors | Reusable unit matchers, referenced as @name in expressions, restrictions and sub-faction modifiers. |
| Sub-choices | Picks an option can offer, defined once (such as a sergeant’s bolter bayonet); their values add to or multiply the option’s cost. |
Resources
A resource is anything that is spent or capped. Its scope decides where it lives: list (points), contingent (HH auxiliary and apex points, granted by roles and special rules and spent by groups) or unit (a per-unit allowance with a capacity stat). Every cost, grant and multiplier uses the same cost editor, which offers the resources whose Used for setting includes that target. With several resources, only those in use show; spending always shows the main one, and + adds another.
Group types and groups
A group type is a kind of container. A root type (e.g. a primary or allied group) starts a contingent; a linked type attaches to roots. A root type's Faction says where its contingent takes its faction from: the list's main faction (the main contingent), an allied faction the player picks (never the main one), or any faction the player picks, the main one included. Only the first is the main contingent, which main in expressions reads. Groups restrict themselves with selectors: a group's unit selector limits every slot, a slot's selector limits that slot, and "requires" lists units the contingent must already hold. Unavailable groups are disabled in the list builder's menus; the builder never removes groups for you. A group's effects (stat, special-rule, trait and slot tag changes) apply to every unit in it, including units in slots a slot option adds; its slot selectors see units before those effects. Its List effects reach units outside it while it's in the list: every unit in the list (allies included) or only in its contingent that a selector matches, right after list choice values. Limit added slots narrows the roles the extra slots of slot options picked in its slots may have; an option left with none isn't offered. A slot's Unit must meet is a condition on the unit filling it, checked as the unit is configured (its upgrades included) and shown as an issue while false. Upgrades are picked after a unit is placed, so a unit that no option could ever make meet it isn't offered, and one that needs an option is offered with the condition's message.
Breaking changes
Deleting an entry, changing an id, a resource's scope, a group type's kind or links, a stat line's stats or a word used in an expression can break other data. The editor checks the game against every faction and sub-faction before and after, and if the change adds errors it lists them in a dialog you must confirm.
The Factions page
A faction's page is a record browser. Ctrl K (or ⌘ K, or Search all above the rail) searches every record by name or id and opens the one you pick. The rail on the left lists each record type with its count; picking one lists its records, with a search box (matching names and ids) and a + button to add one. Units are grouped by role, weapons by stat template and groups by group type, and a dot marks records changed since the last save. Picking a record opens its editor beside the list; a unit's editor is split into Basics, Profiles, Gear and Upgrades tabs, and collapsed upgrades list their options and costs so you can see what a unit offers without opening each one. Records others point at (weapons, equipment, special rules, shared upgrades, named selectors, sub-choices and units) show how many uses they have in the list, and a Used by list under the editor that opens each one; check it before renaming or deleting. Gear names, shared upgrade references and picked special rules (the Open line under them) in an editor open the record they point at. The data checker runs as you edit: a record with problems gets a red count in the list (and a dot on its kind in the rail) and its errors and warnings above its editor. The All, Changed and Has issues buttons above the list narrow it to records changed since the last save or with problems. A sub-faction's page works the same way, with its unit modifiers first.
| Record type | What it holds |
|---|---|
| Units | Profiles (each with an id and a stat template from the game), role, unit type, tags, traits, costs, model count (or composition blocks), default gear, upgrades, restrictions, limits, special rules and a when condition. |
| Weapons and Equipment | Gear records, with weapon profiles. Equipment may carry a weapon profile too, for an attack its rules allow only sometimes (a grenade thrown instead of shooting): add it under Weapon Profile and say in the rules text when it may be used. The list builder shows it as a weapon table marked as equipment; units still hold only the equipment. Units and options point at them. |
| Upgrades | Shared upgrades a unit’s upgrade list can reference instead of copying. |
| Special rules | Rules units can carry. |
| Groups | The faction’s own groups. The default group is the root a new list starts with when the faction is picked; every main faction needs one. |
| Selectors, slot options, sub-choices | Faction-level versions of the Game page’s shared records. A slot option may limit itself to units a selector matches. |
| List rules | Rules like the Game page’s, checked only on the contingents using this faction (or a sub-faction they took). A sub-faction replaces one of its parent’s by declaring it an override. |
Upgrades, options and gear
- An upgrade is a group of options on a unit. Its options can mix concrete options with references to shared faction upgrades, so you write a common gear list once. If ids clash, the upgrade's own option wins, then the first shared upgrade referenced. Hidden options and why are shown in the upgrade editor.
- Options point at the gear they give. Individual models are never tracked, only the amounts of gear the unit holds.
- Restrictions (exclusions and required) target gear, not options, so a bolter satisfies a requirement whichever slot it was taken in. Exclusions only need writing on one side.
Replaceslists sibling upgrades that a non-default pick takes the place of;limit bycaps non-default picks at the amount of some gear held (none held blocks it);swapsreplaces gear the upgrade's profile holds and caps the option at the amount held. A swap may take several gear off at once (+ and, e.g. a pistol and a sword for a pair of claws): each pick takes one of each, so the scarcest caps the picks; that needs validator 1.7.swap fromon the upgrade does the same for every non-default option (shared lists included, unless an option has its own swaps): each pick removes that gear and adds only what the option gives. It needs validator 1.6.- Gear notes say where one use of a weapon sits, such as its mount, without a weapon record per mount. A unit's default gear rows each take a
note, and an upgrade'sGear notegoes with every gear its picks give, swapped-in gear included. A unit upgrade's note wins over that of a shared upgrade it references, so one shared weapon list can be mounted differently on each unit. The list builder shows notes on the unit card's gear line, in the overview and on weapon tables. Notes are display only: restrictions, limits and swaps still count gear by id, and a swap takes off copies under its own upgrade's note first, then those with none. It needs validator 1.11. - Putting an upgrade on a profile (such as the sergeant) puts its gear on that profile and lets restrictions count only matching profiles.
Mirrorsmakes a unit upgrade follow a sibling on another profile, for "every model must have the same item": it always holds the option the other upgrade holds, one per model it counts ("Applied to all models") or one ("Single"), on its own profile and at its own cost per pick. The player never picks it. Put restrictions and limits on the source: the mirror's own still apply and can stop it copying a pick. Both need the same options and default; it needs validator 1.8.- A multi-select upgrade lets several of its options be taken together, and they share a cap: for a "single" upgrade,
Options at once(one per model when left empty), so a one-model vehicle's options take turns unless you raise it. With a cap of 1 the list builder shows the options as a single choice; above it, as checkboxes. Any upgrade holding several picks makes room when full: ticking or raising another option takes from the earliest picks, with an Undo. - In a Some models in unit upgrade with a default, the default holds the models that took nothing else: raising another option takes models from it, lowering one gives them back, and its amount isn't typed.
- An option can offer sub-choices; the list builder shows a picker beside the picked option.
Model counts and composition
A unit is bought with its model count. It can either allow additional models (up to a max, at a cost each, of no particular profile) or be built from composition blocks, not both. A block is a set of models bought together, such as a gun crew of one gunner and one loader: it says how many models of each profile one copy holds, and the unit takes between its min and max copies, paying the block's cost for each copy above min. Each profile belongs in one block. A block can instead replace a model of a profile in another block ("one Thallax may be upgraded to a Praetorian for +10 points"): each copy swaps that many models, so the unit's size stays the same and only its cost changes. With blocks, the model count follows the blocks' minimums, per-model default gear and upgrades put on a profile count that profile's models, and the list builder shows a counter for each block that can grow.
A block's max can be an expression, worked out for the unit as it stands where it sits (in the scopes of the unit's condition), rounded down, with a negative result counting as 0: "for every 5 models in this unit, 1 Procurant may be replaced with 1 Procurator" is a block that replaces a Procurant with max floor(unit.models() / 5). Only a block that replaces models may read unit.models(), and such a block needs a cost. The list builder won't add a copy above the cap; when the cap falls below the copies taken (the unit shrinks), the unit is listed as an issue and keeps its copies until the player takes them off.
Sub-factions
Switch to a faction's Sub-factions view to edit a modifier of it. A sub-faction records which parent versions it was written for. Its records merge over the parent's; a record sharing an id with the parent's should be declared as an intended override. Its unit modifiers pick units with a unit selector (or a named one) and can add a copy of a faction upgrade, apply stat, special-rule or trait effects, or make the units unavailable. The faction and sub-faction views both stay mounted, so unsaved edits survive switching.
A faction can split its sub-factions into sub-faction groups (on the faction view, under the default group), such as a doctrine and a heritage: a contingent takes one of each group, or between the group's min and max. A sub-faction picks its group above its records; without one it is in the default group, taken at most once. Its Can be taken when condition is checked for the contingent taking it (e.g. not main.is(faction:legiones-astartes)).
Slots filled from another faction
A slot can take its units from another faction (Units from, in a group slot's units popover, a slot option's extra slot, or a special rule's Adds slots), optionally with any or some of that faction's sub-factions. Its unit filter then picks among those units, judged on their own records (their own traits only), and the group's unit filter doesn't apply. A borrowed unit keeps its own gear, upgrades and rules but not its sub-faction's unit modifiers; the list's own sub-factions' modifiers apply to it. The slot's effects apply to the unit in it, e.g. replacing its faction trait.
+ Another faction lets the slot take units from several factions in any mix (validator 2.8.0). Each faction then gets its own box with its sub-factions and its own unit filter, which narrows only that faction's units; the slot's unit filter applies to all of them. In the list builder each offered unit names its faction, and a unit whose faction the slot no longer takes is a list issue.
A special rule's Adds slots gives the group of each unit with the rule extra slots (any of their roles), for as long as the unit is there.
Unit selectors and effects
A unit selector matches a unit by unit, role, trait or special rule (any one of those listed, a rule with any value), type or tag (a unit matches when one of its profiles does). Its Except entries leave units out: a unit matching every field of any entry doesn't match, so profiles any of Unique there means "no Unique models". Effects change stats or special rules on the profiles a profile filter picks (a special rule effect takes rules away, exchanges one held for another, then adds one, so "exchange Skirmisher for Armoured (1)" reaches only the models holding Skirmisher), or add, remove or replace the unit's traits; a replacement is only gained by a unit that had one of the replaced traits. Traits match without regard to case. A trait effect with a profile filter (validator 2.9.0) changes only the picked profiles: they gain the trait as their own, or lose it while the other profiles keep it, and its condition can check each profile. A sub-type change (validator 2.10.0) takes sub-types away, then gives others, to the whole unit or, with a profile filter, to the picked profiles; later effects' filters, selectors and tag: references see it, but which models hold gear and which options are offered don't change. A slot option can have one too (validator 2.11.0): it comes last, so it reaches that option's later effects, list rules, other expressions' tag: references and the unit card, but not the slot options offered or the option's own units filter and condition. One model (validator 2.10.0; in slot options, groups and slots) splits one model (or Models split off) off the first profile its filter picks that has one, into a copy of that profile shown on its own line, named by Shown as or after the profile and what gives it, e.g. "Battle Construct (Lead Construct)". Its stat, special-rule, trait and sub-type changes reach that model only, so they have no profile filter, and their condition can check it as the profile. The unit's models, cost, gear and gear choices stay as they were; when no model can be split off, the pick does nothing and is listed as an issue. A unit takes effects in this order: its sub-faction's modifiers (in the order they're written, so a modifier's condition sees the earlier ones but not the later), list choice values, other groups' list effects, its picked options, its group, its slot, then its slot options. A slot option's own Only when offers it only while it holds (seeing the unit as its units filter does); a pick whose condition stops holding stays, with an issue. Anything with a when condition only applies while the condition holds, judged on the unit as the earlier effects left it (other units count with only their unconditional effects). See Expressions.
Slot tags from effects, and option categories
A Slot tag effect makes the slot that holds the unit count as having one or more of the game's slot tags: it offers their slot options, and slot.is(tag:…) reads true. Add one to a sub-faction's unit modifier, an upgrade option's effects, a group, a slot or a list choice value, with a when such as group.is(type:elite) when it should only hold in some groups. Slot options can't have one: they come last, so a tag they added could never offer anything. If the tag goes away (its condition stops holding, or the unit moves), an option picked through it stays on the slot but no longer counts, and the list shows an issue until the player changes it.
A slot option may name a Category, e.g. honour. A slot's categories for one of its tags (in the slot's settings) and a slot tag effect's Only categories limit what that tag offers to options of those categories. Where several limits apply to one tag on one slot, only options every one allows are offered; a source without categories limits nothing. An option without a category is only offered where its tag isn't limited.
Typed rules or expressions?
Prefer the typed form whenever it exists. It enforces itself, fixes picks for you and gives clearer messages.
| You want to… | Use |
|---|---|
| forbid or require gear on a unit | restrictions (exclusions / required) |
| cap an upgrade by what the unit holds | limit by |
| let some units take a slot option without a tagged slot | a slot tag effect (with categories and a when) |
| cap spending, e.g. at a share of the points limit | a resource cap list rule |
| limit how many of a thing the list may hold | a count list rule, or a min / max on the group type or group |
| take something only under a condition no typed form expresses (allegiance, counts across the list, limits, models) | an expression |
limit.max: 1 + floor(contingent.count(unit:tactical-squad) / 2)
Checking your data
- Expression fields check themselves as you type (see Expressions → Checking).
npm run validate-data -- <folder>runs the data checker over a source folder (the app runs the same check on every source it loads): ids match keys, every reference resolves, stats match their templates, shared option lists referenced by one upgrade don't clash (a warning) and every expression checks. Run it after hand-editing data files.- After adding a role, unit type, resource or choice, check the group, slot and list-rule editors still show what you expect.
Checking your data repo on GitHub
Publishing your data as a GitHub repository (the kind of data source added in settings)? Add this workflow to it and GitHub checks the data on every push to main and every pull request, with the same validator the app uses. A pull request that breaks the data shows a failed check naming each problem's file and JSON path, so it's caught before anyone loads it.
A repository made from the game template already has this check (it runs the validator pinned in its package.json instead), so this is for a repository you started some other way.
# .github/workflows/validate.yml
# Checks this Force Org data source on every push to main and every pull
# request, with the same validator the app uses:
# https://github.com/Force-Organization-Army-Builder/fo_data_validator
name: Validate data
on:
push:
branches: [main]
pull_request:
jobs:
validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
# @v2 follows the newest 2.x release; pin a tag such as @v2.0.0 to freeze it
- uses: Force-Organization-Army-Builder/fo_data_validator@v2
with:
# the folder holding forceorg.json
source: .
- The repository needs nothing else: no
package.jsonor install step. The validator runs as its own GitHub Action. @v2follows the newest 2.x release, so the check keeps up with the data format. Pin a release such as@v2.0.0to freeze it.- If
forceorg.jsonisn't at the root of the repository, setsourceto its folder. - An extension source is checked against its base: check the base out too (a second
actions/checkoutstep withrepositoryandpath), setsourceto the base's folder and addextends: .for your own.
Expressions
Most rules in the data are typed: restrictions, the "replaces" and "limit by" settings on upgrades, resource caps, count limits and so on. Use those whenever one fits, because they enforce themselves and fix picks automatically. An expression is the escape hatch for a rule no typed form covers: a short formula the app re-evaluates each time the list changes. Expressions only read the list. They can't change it, always finish, and are checked as you type.
1 + floor(root.count(role:troop) / 2) max of a group choice(allegiance) == traitor when of an option contingent.count(@line-infantry) >= 3 when of a stat effect list.limit(points) >= 3000 when of a group 1 + floor(contingent.count(unit:tactical-squad) / 2) max of a unit
Where expressions go
A field that takes an expression is either a number or a condition. Fields that take a number accept a plain number (3) or an expression; once the text is an expression the box is tinted and marked ƒx.
| Field | Found on | Must produce |
|---|---|---|
when | units, upgrades, options, groups, slots, stat and special-rule effects, expression list rules | true or false (a condition) |
min, max | upgrades, options, groups, group types, count list rules, unit limits, slot repeats | a number |
| cost values | unit and option costs, group type and group costs, sub-choice multipliers | a number, zero or more |
grants | special rules that grant contingent resources | a number |
A when is a condition with a message: the reason players see. If it is false for something not yet picked, that thing is shown disabled with the message. If it becomes false for something already in the list, the message appears as a list alert and nothing is removed for you.
Syntax
- Numbers:
3,0.5. There are no negative literals;-3is a minus applied to3. - Arithmetic:
+ - * /. Dividing by zero makes the rule count as not met. - Comparisons:
== != < <= > >=. They can't be chained: writea > 1 and a < 5, not1 < a < 5. - Logic:
and,or,not,true,false. - Conditional:
condition ? a : b. Both branches must have the same type. - Brackets:
( )group parts. From lowest to highest precedence:?:,or,and,not, comparisons,+ -,* /, unary-.
There are no variables, strings, loops, user-defined functions or property access such as unit.name. The . only joins a scope to a function.
Types
| Type | Values | Produced by |
|---|---|---|
| number | decimals | literals, arithmetic, count, sum, limit, models, picks, value, floor, ceil, min, max |
| bool | true / false | comparisons, and / or / not, has, is |
| choice value | the values of one list choice or sub-choice | choice(name), option.choice(name) |
- Arithmetic and
< <= > >=take numbers. ==and!=compare two numbers, two bools, or a choice with one of its values written bare:choice(allegiance) == traitor. A value that isn't one of the choice's gets a "did you mean" hint. Choices can't be ordered with<.and,or,notand the test of?:take bools.- There are no automatic conversions:
true + 1is an error. - A reference such as
role:troopisn't a value. It can only be an argument to a function.
Scopes
A scope is a view of the list from where the rule sits. You call a function on one: scope.function(args). A field sees its own subject and everything that contains it, so an option can see option, unit, slot and so on up to list, while a list rule sees only list.
| Scope | Is | Functions |
|---|---|---|
rule | the special rule on the unit, in that rule's grants | value() |
option | the option being priced or allowed | picks(), choice(sub-choice) |
profile | the profile an upgrade belongs to (only where the upgrade has a profile) | count(), has(), is() |
unit | the unit being built or considered | count(), has(), is(), sum(), limit(), models() |
slot | the slot the unit fills | is() |
group | the unit’s container (a detachment in HH) | count(), has(), is(), sum() |
contingent | a root group plus the groups linked to it, sharing one faction source | count(), has(), is(), sum() |
main | the list’s main contingent, wherever the rule sits (e.g. from inside an allied one) | count(), has(), is(), sum() |
root | the contingent's root group (HH's primary detachment) | count(), has(), is(), sum() |
list | the whole list | count(), has(), is(), sum(), limit() |
Using a function a scope doesn't have is an error that lists the ones it does.
The game's own words
A game can give a scope its own word under Definition → Terms. In Horus Heresy, detachment means group and primary means root, so primary.count(role:troop) and root.count(role:troop) are the same. The word also works as a reference kind: detachment:auxiliary is group:auxiliary.
Which scopes each field can use
| The expression is on… | Scopes available |
|---|---|
| A group’s when | contingent, root, main, list |
| A group’s min / max | group, contingent, root, main, list |
| A slot (when, repeat max) and slot options | slot, group, contingent, root, main, list |
| A unit (when, limit, cost) | unit, slot, group, contingent, root, main, list |
| An upgrade (when, min, max) | the unit’s scopes, plus profile when the upgrade is on a profile |
| An option (when, max, cost) and sub-choices | option, plus everything an upgrade sees |
| A stat or special-rule effect’s when | profile, unit, slot, group, contingent, root, main, list |
| A trait effect’s when | unit, slot, group, contingent, root, main, list (traits belong to the whole unit, so no profile) |
| A special rule’s grants | rule, unit, slot, group, contingent, root, main, list |
| A group type’s min / max, and list rules | main, list (a count rule limited to a contingent or group also sees those and root) |
| An expression list rule checked for each group | group, contingent, root, main, list |
| A sub-faction’s when, and a sub-faction group’s min / max | contingent, root, main, list (the contingent taking it) |
Using another scope is an error such as "unit isn't available here (allowed: contingent, list, root)".
Functions on a scope
| Function | On | Takes | Returns |
|---|---|---|---|
count(ref) | group, contingent, root, main, list | a unit reference (unit:, role:, type:, tag:, trait:, @selector) | number of matching units in scope |
| profile, unit, group, contingent, root, main, list | a gear reference (weapon:, equipment:) | amount of that gear held, counted as the restriction engine counts it (default gear, plus picks, minus swaps) | |
| contingent, main, list | a group reference (group:) | number of groups of that type or record | |
has(ref) | same as count | same as count | bool, count(ref) > 0 |
is(ref) | unit | unit:, role:, type:, tag:, trait:, @selector | bool: the unit matches |
| profile | type:, tag:, trait: | bool: the profile (with its unit’s type and tags) matches; trait: tests its unit’s traits | |
| slot | tag:, role: | bool: the slot has that tag / accepts that role | |
| group, root | type:, group: | bool: the group is of that type or record | |
| contingent, main, list | faction:, subfaction: | bool: the contingent’s faction source (main and list: the list’s main one) | |
sum(resource, ref?) | unit, group, contingent, root, main, list | a resource id, and optionally a unit reference (not on unit) | resource spent in scope, optionally only on matching units |
limit(resource) | list | a list-scope resource | the player’s limit, e.g. the points limit |
| unit | a unit-scope resource | the unit’s capacity, from the resource’s capacity stat | |
models() | unit | nothing | models in the unit, including additional models (with composition blocks: every copy of every block) |
picks() | option | nothing | times the option has been taken |
choice(sub-choice) | option | a sub-choice id | the option's sub-choice value, e.g. option.choice(facing) == turret |
value() | rule | nothing | the rule's value on the unit, or its default value. An error (the grant counts as 0) when it has neither, or isn't a number |
Global functions
These need no scope.
| Function | Returns | Notes |
|---|---|---|
choice(name) | a choice value | The list's pick for one of the game's list choices (HH: choice(allegiance)). Compare it with one of its values: choice(allegiance) == loyalist. If the list hasn't set the choice, the rule counts as not met. |
floor(x) | number | rounds down |
ceil(x) | number | rounds up |
min(a, b, …) | number | the smallest of two or more numbers |
max(a, b, …) | number | the largest of two or more numbers |
References and selectors
Functions find records through a reference: kind:id with no spaces. An @id refers to a named selector. References are only valid as function arguments.
| Reference | Means | Defined in |
|---|---|---|
unit:id | a unit | the faction / sub-faction |
role:id | a role | Game → Roles |
type:id | a unit type — or, on group and root, a group type | Game → Unit types / Group types |
tag:id | a unit or profile tag — or, on slot, a slot tag | unit and profile tags / Game → Slot tags |
trait:id | a unit trait, as the unit has it with its effects applied | unit traits, and trait effects’ add / replace |
weapon:id | a weapon | the faction |
equipment:id | a piece of equipment | the faction |
group:id | a group type or a specific group (or the game’s word, e.g. detachment:id) | Game → Group types / Groups |
faction:id / subfaction:id | a faction / sub-faction | the data in use |
@id | a named selector | the faction (with its sub-faction), then the game |
The same kind can mean different things on different scopes. type: is a unit type on unit and profile, and a group type on group and root. Unknown ids give a "did you mean" hint.
Unit tags are free text (Heavy Assault), so a tag: reference writes them in id form, lowercase with hyphens (tag:heavy-assault), and matches case-insensitively. A tag no unit has is a warning, not an error. Traits work the same way: trait:infantry-tercio matches a unit with the Infantry Tercio trait, whether it's on the unit or an effect gave it. Other units count with only their unconditional effects.
Named selectors (Game or faction → Named Selectors) give a unit selector a name so many rules can share it. Use one anywhere a unit reference fits: contingent.count(@line-infantry).
Default values in your game
Beyond the fixed scopes, functions and reference kinds, the names you can use come from the game's data. These are the ones defined right now.
How expressions are evaluated
- Live. Expressions are re-evaluated whenever the list changes.
- Candidates as if placed. A unit in the picker is evaluated as if it were already in the slot; a group in the Add menu as if it were in the list.
- Rounding. A
minormaxthat isn't a whole number is rounded down. Usefloororceilto be explicit. - Costs must come out zero or more.
- Errors don't crash the builder. Division by zero, a negative cost or a scope that doesn't exist yet counts the rule as not met:
whenis false,maxis 0, aminis unmet, or the item can't be priced. - The same list and data always give the same result.
Checking and warnings
Every expression field is checked as you type. Problems are underlined in the box and listed under it: red errors mean the rule can't work, and ochre warnings point out a better way. The checker reports unknown names, scopes the field can't use, functions a scope doesn't have, bad references, type mismatches and the wrong result type for the field (a max that gives true/false, say).
Warnings steer you to the typed rule when one exists:
| If an expression is… | Use instead |
|---|---|
an option or upgrade when of not unit.has(weapon:x) | an exclusion in the restrictions |
an option or upgrade when of unit.has(weapon:x) | a requirement in the restrictions |
list.sum(R, …) <= list.limit(R) * N | a resource cap list rule |
a list rule list.count(ref) <= N | a count list rule |
| a comparison that is always true or false (a count compared with a negative number) | remove it, or fix the condition |
Renaming or deleting something an expression names (a role, resource, choice value, unit…) is a breaking change. The editor warns you and lists the expressions that would stop working before it lets you confirm.
Recipes
max: 1 + floor(root.count(role:troop) / 2)
when.if: choice(allegiance) == traitor when.message: Traitor armies only
when.if: list.limit(points) >= 3000 when.message: Needs an army of 3000 points or more
when.if: group.count(unit:tactical-squad) >= 1 when.message: Needs a Tactical Squad in this group
unit.has(weapon:lascannon) ? 25 : 15
floor(unit.models() / 5)
when.if: group.is(type:primary)