DUMMYNATION Scripting reference

Scripting reference

Scripts are event-driven rules for custom scenarios. This reference explains the format the script editor saves, for modders and anyone who wants to read, write or generate scripts by hand.

Generated from the game's script catalogs. Ids, field names and keywords are the same in every language.

Getting started

What scripts are

Scripts are event-driven rules for Dummynation scenarios and mods. Each script waits for a trigger (an event such as a new game starting or a war being declared), checks a condition, and runs a list of actions. Functions are reusable calculations that scripts call.

This schema describes the scripts.json file saved with a custom scenario, and everything inside it: scripts, functions, typed values, conditions, actions, and the full catalogs of commands, expression methods and triggers. The same definitions appear in the SCRIPT, SCRIPT_SOURCE and SCRIPT_FUNCTION roots of a scenario patch (see $defs/scriptPatch).

The in-game script editor reads and writes this format, so building a script there and inspecting the saved file is the quickest way to learn it. Saved files keep scripts in the compact source format (the source property) and functions as JSON. Both forms describe the same tree, and either is accepted when loading.

Use the schema in an editor

The whole reference is also published as a JSON Schema (draft 2020-12). Point a file at it with $schema, and editors that support JSON Schema, such as Visual Studio Code, offer completion, show these explanations on hover and mark mistakes as you type.

{"$schema":"https://dummynation.ahfgames.com/scripting/scripts.schema.json","scripts":[]}

The schema checks the structure, ids, required fields, argument counts and result types. The game checks a few things a schema cannot: which trigger parameters a script may read, the type of each argument, and whether a called function exists. Use $defs/scriptPatch from the same file to check the scripting roots of a scenario patch.

The scripts.json file

A custom scenario saves its scripts in scripts.json. These are its top-level fields.

FieldTypeRequiredDescription
$schemastringOptional link to this schema, so editors such as Visual Studio Code offer completion and validation.
sourcecompact sourceScripts in compact source form. This is how the game saves them.
sourcescompact sourceAdditional compact source modules, loaded after source.
scriptslist of scriptScripts as JSON trees. Each one replaces any script with the same id read before it.
functionslist of functionReusable functions. Their ids must be unique.
stateruntime stateSaved runtime state, written by the game. Leave it out when authoring a scenario.

A complete example

Two scripts and one function: a welcome message in two languages, and a monthly reward for large countries that uses a reusable check.

{
  "scripts": [
    {
      "id": "welcome",
      "trigger": "GAME_STARTED",
      "runPolicy": "ONCE",
      "actions": [
        {
          "kind": "MESSAGE",
          "text": "{\"en\":\"Welcome, commander.\",\"es\":\"Bienvenido, comandante.\"}"
        }
      ]
    },
    {
      "id": "reward_growth",
      "trigger": "COUNTRY_DAILY_UPDATE",
      "cooldownDays": 30,
      "condition": {
        "kind": "VALUE",
        "left": {
          "kind": "CALL",
          "type": "BOOLEAN",
          "value": "is_large",
          "args": [
            {
              "kind": "PARAM",
              "type": "COUNTRY",
              "param": "COUNTRY"
            }
          ]
        }
      },
      "actions": [
        {
          "kind": "COMMAND",
          "command": {
            "id": "country.modify_data",
            "values": {
              "country": {
                "kind": "PARAM",
                "type": "COUNTRY",
                "param": "COUNTRY"
              },
              "field": {
                "kind": "CONSTANT",
                "type": "STRING",
                "value": "money"
              },
              "operation": {
                "kind": "CONSTANT",
                "type": "STRING",
                "value": "ADD"
              },
              "amount": {
                "kind": "CONSTANT",
                "type": "NUMBER",
                "value": "1000"
              }
            }
          }
        }
      ]
    }
  ],
  "functions": [
    {
      "id": "is_large",
      "returnType": "BOOLEAN",
      "parameters": [
        {
          "name": "country",
          "type": "COUNTRY"
        }
      ],
      "condition": {
        "kind": "VALUE",
        "left": {
          "kind": "CALL",
          "type": "BOOLEAN",
          "value": "number.greater_equal",
          "args": [
            {
              "kind": "CALL",
              "type": "NUMBER",
              "value": "country.population",
              "args": [
                {
                  "kind": "VARIABLE",
                  "type": "COUNTRY",
                  "value": "country"
                }
              ]
            },
            {
              "kind": "CONSTANT",
              "type": "NUMBER",
              "value": "50000000"
            }
          ]
        }
      }
    }
  ]
}

Scripts and functions

Script fields

A rule: when TRIGGER fires and CONDITION passes, run ACTIONS in order. Omitted fields use their defaults.

FieldTypeRequiredDescription
idstringYesUnique script id. Commands such as script.set_enabled refer to it.
enabledbooleanDisabled scripts never run. Disabling a script also removes the map overlays it drew. Default: true.
triggertriggerThe event that starts this script. It decides which trigger parameters (PARAM values) are available. Default: DAILY_UPDATE.
runPolicyrun policyDefault: "REPEAT".
cooldownDaysintegerMinimum game days between two successful runs. 0 means no cooldown. Like runPolicy and maxRuns, it counts all runs of the script together, not per country: use a registry keyed by country for per-country limits. Default: 0.
maxRunsintegerMaximum number of successful runs. 0 means unlimited. Default: 0.
conditionCondition or nullChecked each time the trigger fires; the actions run only when it passes. Omit it (or use null in a patch) to always pass.
actionslist of ActionActions run from first to last. Later actions can use variables and objects created by earlier ones.

Run policy

REPEAT allows any number of runs (subject to cooldownDays and maxRuns); ONCE allows one successful run in total.

ValueMeaning
REPEATRun every time the trigger fires and the condition passes.
ONCERun only the first time the condition passes.

Functions

A reusable calculation with typed parameters and a typed result. Call it from any value with {"kind":"CALL","value":"FUNCTION_ID","args":[...]}, passing arguments in parameter order. Functions have no trigger and cannot call themselves, directly or indirectly.

FieldTypeRequiredDescription
idstringYesUnique function id, used as the value of CALL nodes. Choose ids that do not clash with built-in method ids.
returnTypevalue typeType of the result. Default: BOOLEAN. BOOLEAN functions return their condition; every other type returns value.
returnElementTypevalue typeItem type of the result when returnType is LIST.
parameterslist of function parameterInputs, in call order. Inside the function each parameter is a local variable: read it with {"kind":"VARIABLE","value":"NAME"}.
actionslist of ActionSetup statements run before the result is computed, for example to store intermediate local variables. They must not change the game: functions are calculations.
conditionConditionResult of a BOOLEAN function. Omit it to return true.
valueValueResult of a function whose returnType is not BOOLEAN. Its type must match returnType.

Function parameters

One function input.

FieldTypeRequiredDescription
namestringYesParameter name. It becomes a local variable inside the function.
typevalue typeParameter type.
elementTypevalue typeItem type when type is LIST.
paramstringInternal link to a trigger parameter. Not used by functions.

Scenario patches

A scenario patch is a JSON object whose roots edit different parts of a scenario. These three roots edit scripts; other roots are ignored by this schema. Roots are applied in this order: SCRIPT_FUNCTION, SCRIPT_SOURCE, SCRIPT.

SCRIPT edits scripts by id. Each property name is an id: an object edits that script (creating it if needed), and null or false removes it. Edits are partial: fields you leave out keep their current values, unless the entry sets $replace to true.

FieldTypeRequiredDescription
$addlist of script or objectMore scripts to add or edit: a list of definitions with an id, or an object keyed by id.
$removestring or list of stringIds of scripts to remove.
$clearbooleantrue removes every existing script before the other edits.

Entry fields

FieldTypeRequiredDescription
idstringRenames the script.
$replacebooleantrue replaces the whole definition, so omitted fields return to their defaults.
$removebooleantrue removes the script.
$deletebooleanSame as $remove.
{
  "SCRIPT": {
    "welcome": {
      "trigger": "GAME_STARTED",
      "runPolicy": "ONCE",
      "actions": [
        {
          "kind": "MESSAGE",
          "text": "Welcome to the scenario."
        }
      ]
    },
    "old_rule": null
  }
}
{
  "SCRIPT_SOURCE": "(dscript 1 (script welcome 1 GAME_STARTED ONCE 0 1 true (message \"Welcome to the scenario.\")))"
}

Values

Value nodes

A typed expression. Values appear wherever a script reads data: command fields, method arguments, conditions and variables. Every node has a kind (where the value comes from) and a type (what it produces); the other fields depend on the kind.

{"kind":"CONSTANT","type":"NUMBER","value":"12"}
{"kind":"PARAM","type":"COUNTRY","param":"COUNTRY"}
{"kind":"CALL","type":"NUMBER","value":"country.population","args":[{"kind":"PARAM","type":"COUNTRY","param":"COUNTRY"}]}
{"kind":"CONSTANT","type":"LIST","elementType":"POINT","value":"120,90;140.25,95.75"}

CONSTANT

A fixed literal written in value, interpreted according to type.

A literal. value always holds text, which is read according to type: see each value type for its literal format. Numbers and booleans are therefore written as strings, for example "12" or "true". Only lists of points can be written as constants ("x,y;x,y"); an empty value is an empty or missing value.

FieldTypeRequiredDescription
valuestringThe literal, as text. Default: "".

PARAM

A parameter of the trigger that started the script, named by param.

Reads a parameter of the trigger that started the script. The trigger must provide it.

FieldTypeRequiredDescription
paramtrigger parameter
valuestringOlder files name the parameter here (its lowercase id) instead of in param.
namestringOlder spelling of value.

VARIABLE

A local variable: one stored earlier in this run with SET_VARIABLE, a function parameter, a loop variable, or a variable created by a command.

Reads a local variable, a shared variable or a registry by name.

FieldTypeRequiredDescription
valuestringVariable or registry name. Names start with a letter or underscore and continue with letters, digits or underscores.

GLOBAL_VARIABLE

A shared variable stored with SET_GLOBAL_VARIABLE. Shared variables are visible to every script and are saved with the game.

Reads a local variable, a shared variable or a registry by name.

FieldTypeRequiredDescription
valuestringVariable or registry name. Names start with a letter or underscore and continue with letters, digits or underscores.

REGISTRY

A registry (a saved key-value table) by name. Read its entries with the REGISTRY methods.

Reads a local variable, a shared variable or a registry by name.

FieldTypeRequiredDescription
valuestringVariable or registry name. Names start with a letter or underscore and continue with letters, digits or underscores.

GLOBAL

A value provided by the game engine, such as the current day or the list of countries.

Reads a value provided by the game engine. These are not saved script state: for that, use GLOBAL_VARIABLE.

FieldTypeRequiredDescription
valueone of the values belowEngine value id.

Engine values

IdMeaning
dayNUMBER: days elapsed since the start of the game.
dateDATE: the current game date.
deltaNUMBER: length of the current simulation step.
playerCOUNTRY: the local player's country. It differs between players, so use it only for displays (messages, HUD, overlays), never for rules that change the game in multiplayer.
waterCOUNTRY: the empty country used for water and unowned land (same as null).
nullCOUNTRY: the empty country.
uninhabitableCOUNTRY: the country that owns uninhabitable land.
countriesLIST of COUNTRY: every country slot of the map.
active_countriesLIST of COUNTRY: the countries currently in the game.
squadsLIST of SQUAD: every squad in the world.
coalitionsLIST of COALITION: every coalition.
rankingsRANKINGS: the world rankings.
economyWORLD_ECONOMY: world economy totals.
gameGAME: the running game.
mapMAP: the world map.
activecountriesAlias of active_countries.
all_squadsAlias of squads.
allsquadsAlias of squads.
world_economyAlias of economy.

COLLECTION_QUERY

Filters, searches or aggregates a list, described by query.

Runs a collection query. Its type and elementType follow from the query operation.

FieldTypeRequiredDescription
querycollection queryYes

CALL

Calls an expression method or one of your functions, with arguments in args.

Calls an expression method or a function. Arguments are values in signature order. To chain, nest calls: a method that reads from an object takes that object as its first argument.

FieldTypeRequiredDescription
valuemethod id or stringYesMethod id (see methodId) or the id of one of your functions.
argslist of ValueArguments, in the order of the method's signature or the function's parameters.

Collection queries

Processes a list (or the numbers 0 to n-1 when collection is a NUMBER). For every item, variable holds the item while filter and map are evaluated.

OperationMeaning
FILTERLIST of the items that pass filter (the original items, not mapped values).
FIRSTThe first item that passes filter, or null.
RANDOMA random item that passes filter, using the game's random generator.
COUNTNUMBER of items that pass filter.
SUMNUMBER: sum of map over the items that pass filter.
AVERAGENUMBER: average of map over the items that pass filter.
MINNUMBER: smallest map result.
MAXNUMBER: largest map result.
MIN_ITEMThe item with the smallest map result.
MAX_ITEMThe item with the largest map result.
FieldTypeRequiredDescription
variablestringName of the local variable holding the current item. When omitted, a name based on the item type is used; naming it explicitly keeps nested queries readable.
collectionValueYesThe LIST to process, or a NUMBER n to process 0 to n-1.
filterConditionItems must pass this condition. Omit it to include every item.
mapValueNUMBER computed per item. Required by SUM, AVERAGE, MIN, MAX, MIN_ITEM and MAX_ITEM; unused by the others.
{
  "operation": "COUNT",
  "variable": "c",
  "collection": {
    "kind": "GLOBAL",
    "type": "LIST",
    "elementType": "COUNTRY",
    "value": "active_countries"
  },
  "filter": {
    "kind": "VALUE",
    "left": {
      "kind": "CALL",
      "type": "BOOLEAN",
      "value": "number.greater",
      "args": [
        {
          "kind": "CALL",
          "type": "NUMBER",
          "value": "country.population",
          "args": [
            {
              "kind": "VARIABLE",
              "type": "COUNTRY",
              "value": "c"
            }
          ]
        },
        {
          "kind": "CONSTANT",
          "type": "NUMBER",
          "value": "100000000"
        }
      ]
    }
  }
}

Conditions

Condition nodes

A yes/no test built from values. Conditions decide whether a script runs, guard IF actions, filter collection queries and form the result of BOOLEAN functions.

{
  "kind": "AND",
  "children": [
    {
      "kind": "VALUE",
      "left": {
        "kind": "CALL",
        "type": "BOOLEAN",
        "value": "country.equal",
        "args": [
          {
            "kind": "PARAM",
            "type": "COUNTRY",
            "param": "COUNTRY"
          },
          {
            "kind": "CONSTANT",
            "type": "COUNTRY",
            "value": "France"
          }
        ]
      }
    },
    {
      "kind": "NOT",
      "children": [
        {
          "kind": "VALUE",
          "left": {
            "kind": "CALL",
            "type": "BOOLEAN",
            "value": "country.is_dead",
            "args": [
              {
                "kind": "PARAM",
                "type": "COUNTRY",
                "param": "COUNTRY"
              }
            ]
          }
        }
      ]
    }
  ]
}

ALWAYS

Always passes. This is the default condition.

VALUE

Passes when left evaluates to true. Comparisons are BOOLEAN methods such as number.greater or country.equal.

FieldTypeRequiredDescription
leftValueYesBOOLEAN value to test.

NOT

Passes when its child fails.

FieldTypeRequiredDescription
childrenlist of ConditionNested conditions.

AND

Passes when every child passes.

FieldTypeRequiredDescription
childrenlist of ConditionNested conditions.

OR

Passes when at least one child passes.

FieldTypeRequiredDescription
childrenlist of ConditionNested conditions.

XOR

Passes when an odd number of children pass (with two children: exactly one).

FieldTypeRequiredDescription
childrenlist of ConditionNested conditions.

EVERY_IN_COLLECTION

Passes when every item of value passes all children. True for an empty list.

FieldTypeRequiredDescription
variablestringName of the local variable holding the current item. Name it explicitly; when omitted a name based on the item type is used.
valueValueYesThe LIST to check, or a NUMBER n to check 0 to n-1.
childrenlist of ConditionNested conditions.

ANY_IN_COLLECTION

Passes when at least one item of value passes all children. False for an empty list.

FieldTypeRequiredDescription
variablestringName of the local variable holding the current item. Name it explicitly; when omitted a name based on the item type is used.
valueValueYesThe LIST to check, or a NUMBER n to check 0 to n-1.
childrenlist of ConditionNested conditions.

COUNT_IN_COLLECTION

Counts the items of value that pass all children, stores the number in the local variable count, then passes when left (a BOOLEAN that can read count) is true.

FieldTypeRequiredDescription
variablestringName of the local variable holding the current item. Name it explicitly; when omitted a name based on the item type is used.
valueValueYesThe LIST to check, or a NUMBER n to check 0 to n-1.
childrenlist of ConditionNested conditions.
leftValueYesBOOLEAN test evaluated after counting; read the local variable count, for example count >= 3.

Actions

Action nodes

One step of a script. Actions run from first to last.

{"kind":"MESSAGE","text":"Day ${game.day}: ${var.leader} leads the world."}
{"kind":"SET_VARIABLE","variable":"leader","value":{"kind":"PARAM","type":"COUNTRY","param":"COUNTRY"}}

NOOP

Does nothing.

PATCH

Applies a scenario patch written as JSON in text. Placeholders are filled in before it is applied. An advanced escape hatch: prefer COMMAND.

FieldTypeRequiredDescription
texttextFor PATCH: the patch JSON. For messages: the message text, with placeholders and localized text.

COMMAND

Runs a structured command from the command catalog. This is how scripts change the game.

FieldTypeRequiredDescription
commandcommandYes

Every command, with its fields, is listed in the commands reference.

{
  "id": "country.set_color",
  "values": {
    "country": {
      "kind": "PARAM",
      "type": "COUNTRY",
      "param": "COUNTRY"
    },
    "color": {
      "kind": "CONSTANT",
      "type": "COLOR",
      "value": "2563ebff"
    }
  }
}

MESSAGE

Shows a notification with text.

FieldTypeRequiredDescription
texttextFor PATCH: the patch JSON. For messages: the message text, with placeholders and localized text.

WARN_MESSAGE

Shows a warning notification with text.

FieldTypeRequiredDescription
texttextFor PATCH: the patch JSON. For messages: the message text, with placeholders and localized text.

ALERT_MESSAGE

Shows an alert notification with text.

FieldTypeRequiredDescription
texttextFor PATCH: the patch JSON. For messages: the message text, with placeholders and localized text.

SET_VARIABLE

Stores value in a local variable, available to later actions of the same run.

FieldTypeRequiredDescription
variablestringYesVariable name. Names start with a letter or underscore and continue with letters, digits or underscores; engine value names such as day or player are reserved.
valueValueYesValue to store. The variable takes its type.

SET_GLOBAL_VARIABLE

Stores value in a shared variable, visible to every script and saved with the game.

FieldTypeRequiredDescription
variablestringYesVariable name. Names start with a letter or underscore and continue with letters, digits or underscores; engine value names such as day or player are reserved.
valueValueYesValue to store. The variable takes its type.

SET_REGISTRY

Changes an entry of a registry, a saved key-value table.

Registries are saved key-value tables shared by all scripts, useful for per-country state (key them by country). Read them with REGISTRY values and the REGISTRY methods. The registries named script_hud_widgets and script_messages belong to the HUD and message commands: do not write them directly.

FieldTypeRequiredDescription
textone of the values belowOperation. Default: set. Default: "set".
variablestringYesRegistry name.
keyValueEntry key. While value is evaluated, the local variable key holds it.
valueValueValue to store (set and append).

IF

Runs actions only when condition passes.

FieldTypeRequiredDescription
conditionConditionYes
actionslist of ActionNested actions, run in order.

FOR_EACH

Runs actions once per item of value.

Each iteration has its own local scope: variables set inside the loop are discarded afterwards. Use shared variables or registries to keep results.

FieldTypeRequiredDescription
variablestringName of the local variable holding the current item. Name it explicitly; when omitted a name based on the item type is used.
valueValueYesThe LIST to iterate, or a NUMBER n to iterate 0 to n-1.
actionslist of ActionNested actions, run in order.

Land selections

One piece of land for a map command. kind says how the land is chosen; source and ownerFilter restrict whose land is taken.

KindMeaning
POLYGONCells inside the polygon given by value (LIST of POINT).
PATHCells along the path given by value (LIST of POINT).
POINTSThe cells given by value (LIST of POINT).
REGIONThe province or region named by value (STRING).
TARGETAll land of the source country.
FieldTypeRequiredDescription
valueValueThe points (LIST of POINT) or the region name (STRING), depending on kind.
sourceValueOptional COUNTRY: only land owned by this country is selected. Required by TARGET.
ownerFilterValueOptional BOOLEAN evaluated for every cell, with the local variables owner (COUNTRY), point (POINT), x and y (NUMBER). Cells where it is false are skipped.
{
  "kind": "POLYGON",
  "value": {
    "kind": "CONSTANT",
    "type": "LIST",
    "elementType": "POINT",
    "value": "900,550;1000,550;1000,650;900,650"
  },
  "source": {
    "kind": "CONSTANT",
    "type": "COUNTRY",
    "value": "United_States_of_America"
  }
}

Paint strokes

One dab of the map paint brush, replayed when a map.paint_* command runs. The editor records these while you paint.

FieldTypeRequiredDescription
xnumberYesBrush center, in map cells.
ynumberYesBrush center, in map cells.
sizenumberBrush diameter in cells. Default: 8.
hardnessstringFalloff curve from the center to the edge. Unknown names use LINEAR. Default: "LINEAR".
noisenumberRandom variation of the brush strength. Default: 0.1.
operationstringHow the painted value combines with the current one. Default: "SET".
valuestringPainted value: a number, or a land cover / ocean id for those commands.
middleValuestringOptional value for the middle ring of the brush.
weakValuestringOptional value for the outer ring of the brush.

Triggers

GAME_STARTED

New game started. Runs when a new game starts: use it for setup such as overlays, widgets or starting conditions.

This trigger provides no parameters.

GAME_ENDED

Game ended. Runs after the result has been decided.

ParameterType
WINNERCOUNTRY

DAILY_UPDATE

Daily update. Runs once per game day.

ParameterType
DAYNUMBER
DATEDATE

COUNTRY_DAILY_UPDATE

Daily country update. Runs once per game day for every country, so its cost grows with the number of countries. Keep the condition cheap, and prefer an event trigger when one matches.

COUNTRY_DIED

Country died.

ParameterType
COUNTRYCOUNTRY

COUNTRY_REVIVED

Country revived.

ParameterType
COUNTRYCOUNTRY

COUNTRY_ADDED

Country added.

ParameterType
COUNTRYCOUNTRY

COUNTRY_REMOVED

Country removed.

ParameterType
COUNTRYCOUNTRY

PLAYER_COUNTRY_CHANGED

Player country changed.

ParameterType
COUNTRYCOUNTRY

CLAIM_ADDED

Claim added.

CLAIM_REMOVED

Claim removed.

DIPLOMACY_STATUS_CHANGED

Diplomacy status changed.

ALLIANCE_STARTED

Alliance started.

ALLIANCE_ENDED

Alliance ended.

WAR_STARTED

War started.

WAR_ENDED

War ended.

COUNTRY_LIBERATED

Country liberated.

COUNTRY_PUPPETED

Country puppeted.

COUNTRY_UNPUPPETED

Country released from master.

SQUAD_CREATED

Squad created.

SQUAD_REMOVED

Squad removed.

SQUAD_SPLIT

Squad split.

SQUAD_MOVED

Squad moved.

SQUAD_DIED

Squad died.

TECH_RESEARCHED

Technology researched.

AOE_DEVELOPED

Area effect developed.

UNIT_RESEARCHED

Unit researched.

POINT_ANNEXED

Point annexed.

BATTLE_STARTED

Battle started.

BATTLE_UPDATED

Battle updated.

BATTLE_ENDED

Battle ended.

INVASION_STARTED

Invasion started.

INVASION_UPDATED

Invasion updated.

INVASION_ENDED

Invasion ended.

IDEOLOGY_CHANGED

Ideology changed.

LEADER_CHANGED

Leader changed.

GAME_ENDING

Game ending. Runs just before a normal victory or defeat is decided. script.cancel_game_end cancels it while this trigger runs, so the scenario can continue or end later with script.end_game.

WAR_DECLARED

War declared by aggressor.

COALITION_MEMBERSHIP_CHANGED

Coalition membership changed.

This trigger provides no parameters.

Trigger parameters

WINNER

Winner. In text placeholders: ${param.winner}. Type COUNTRY. Provided by GAME_ENDED, GAME_ENDING.

COUNTRY

Country. In text placeholders: ${param.country}. Type COUNTRY. Provided by COUNTRY_DAILY_UPDATE, COUNTRY_DIED, COUNTRY_REVIVED, COUNTRY_ADDED, COUNTRY_REMOVED, PLAYER_COUNTRY_CHANGED, CLAIM_ADDED, CLAIM_REMOVED, DIPLOMACY_STATUS_CHANGED, ALLIANCE_STARTED, ALLIANCE_ENDED, WAR_STARTED, WAR_ENDED, COUNTRY_LIBERATED, COUNTRY_PUPPETED, COUNTRY_UNPUPPETED, TECH_RESEARCHED, AOE_DEVELOPED, UNIT_RESEARCHED, IDEOLOGY_CHANGED, LEADER_CHANGED, WAR_DECLARED.

TARGET

Target. In text placeholders: ${param.target}. Type COUNTRY. Provided by CLAIM_ADDED, CLAIM_REMOVED, DIPLOMACY_STATUS_CHANGED, ALLIANCE_STARTED, ALLIANCE_ENDED, WAR_STARTED, WAR_ENDED, COUNTRY_LIBERATED, COUNTRY_PUPPETED, COUNTRY_UNPUPPETED, WAR_DECLARED.

SQUAD

Squad. In text placeholders: ${param.squad}. Type SQUAD. Provided by SQUAD_CREATED, SQUAD_REMOVED, SQUAD_SPLIT, SQUAD_MOVED, SQUAD_DIED, INVASION_STARTED, INVASION_UPDATED, INVASION_ENDED.

OWNER

Owner. In text placeholders: ${param.owner}. Type COUNTRY. Provided by SQUAD_CREATED, SQUAD_REMOVED, SQUAD_SPLIT, SQUAD_MOVED, SQUAD_DIED.

X

X. In text placeholders: ${param.x}. Type NUMBER. Provided by SQUAD_CREATED, SQUAD_REMOVED, SQUAD_SPLIT, SQUAD_MOVED, SQUAD_DIED, AOE_DEVELOPED, POINT_ANNEXED.

Y

Y. In text placeholders: ${param.y}. Type NUMBER. Provided by SQUAD_CREATED, SQUAD_REMOVED, SQUAD_SPLIT, SQUAD_MOVED, SQUAD_DIED, AOE_DEVELOPED, POINT_ANNEXED.

POINT

Point. In text placeholders: ${param.point}. Type POINT. Provided by AOE_DEVELOPED, POINT_ANNEXED.

LOCATION_COUNTRY

LocationCountry. In text placeholders: ${param.locationCountry}. Type COUNTRY. Provided by SQUAD_CREATED, SQUAD_REMOVED, SQUAD_SPLIT, SQUAD_MOVED, SQUAD_DIED.

PREVIOUS_X

PreviousX. In text placeholders: ${param.previousX}. Type NUMBER. Provided by SQUAD_MOVED.

PREVIOUS_Y

PreviousY. In text placeholders: ${param.previousY}. Type NUMBER. Provided by SQUAD_MOVED.

DAY

Day. In text placeholders: ${param.day}. Type NUMBER. Provided by DAILY_UPDATE, COUNTRY_DAILY_UPDATE, SQUAD_DIED.

DATE

Date. In text placeholders: ${param.date}. Type DATE. Provided by DAILY_UPDATE, COUNTRY_DAILY_UPDATE.

SQUAD_TYPE

SquadType. In text placeholders: ${param.squadType}. Type SQUAD_TYPE. Provided by SQUAD_CREATED, SQUAD_REMOVED, SQUAD_SPLIT, SQUAD_MOVED, SQUAD_DIED.

TASK

Task. In text placeholders: ${param.task}. Type SQUAD_TASK. Provided by SQUAD_CREATED, SQUAD_REMOVED, SQUAD_SPLIT, SQUAD_MOVED, SQUAD_DIED.

TECH

Tech. In text placeholders: ${param.tech}. Type TECHNOLOGY. Provided by TECH_RESEARCHED.

COUNTRY_TECH

CountryTech. In text placeholders: ${param.countryTech}. Type COUNTRY_TECH. Provided by TECH_RESEARCHED.

AOE

Area effect. In text placeholders: ${param.aoe}. Type AOE. Provided by AOE_DEVELOPED.

UNIT

Unit. In text placeholders: ${param.unit}. Type UNIT. Provided by UNIT_RESEARCHED.

ATTACKER

Attacker. In text placeholders: ${param.attacker}. Type COUNTRY. Provided by POINT_ANNEXED, INVASION_STARTED, INVASION_UPDATED, INVASION_ENDED.

DEFENDER

Defender. In text placeholders: ${param.defender}. Type COUNTRY. Provided by POINT_ANNEXED, INVASION_STARTED, INVASION_UPDATED, INVASION_ENDED.

POPULATION

Population. In text placeholders: ${param.population}. Type NUMBER. Provided by POINT_ANNEXED.

LOOT

Loot. In text placeholders: ${param.loot}. Type NUMBER. Provided by POINT_ANNEXED, INVASION_UPDATED, INVASION_ENDED.

ORIGIN

Origin. In text placeholders: ${param.origin}. Type INVASION. Provided by POINT_ANNEXED.

BATTLE

Battle. In text placeholders: ${param.battle}. Type BATTLE. Provided by BATTLE_STARTED, BATTLE_UPDATED, BATTLE_ENDED.

SQUAD1

Squad 1. In text placeholders: ${param.squad1}. Type SQUAD. Provided by BATTLE_STARTED, BATTLE_UPDATED, BATTLE_ENDED.

SQUAD2

Squad 2. In text placeholders: ${param.squad2}. Type SQUAD. Provided by BATTLE_STARTED, BATTLE_UPDATED, BATTLE_ENDED.

COUNTRY1

Country 1. In text placeholders: ${param.country1}. Type COUNTRY. Provided by BATTLE_STARTED, BATTLE_UPDATED, BATTLE_ENDED.

COUNTRY2

Country 2. In text placeholders: ${param.country2}. Type COUNTRY. Provided by BATTLE_STARTED, BATTLE_UPDATED, BATTLE_ENDED.

CASUALTIES1

Casualties1. In text placeholders: ${param.casualties1}. Type NUMBER. Provided by BATTLE_UPDATED.

CASUALTIES2

Casualties2. In text placeholders: ${param.casualties2}. Type NUMBER. Provided by BATTLE_UPDATED.

CASUALTIES

Casualties. In text placeholders: ${param.casualties}. Type NUMBER. Provided by BATTLE_UPDATED.

PERCENT

Percent. In text placeholders: ${param.percent}. Type NUMBER. Provided by AOE_DEVELOPED, BATTLE_UPDATED.

INVASION

Invasion. In text placeholders: ${param.invasion}. Type INVASION. Provided by INVASION_STARTED, INVASION_UPDATED, INVASION_ENDED.

CONQUESTS

Conquests. In text placeholders: ${param.conquests}. Type NUMBER. Provided by INVASION_UPDATED, INVASION_ENDED.

LAST_CONQUESTS

LastConquests. In text placeholders: ${param.lastConquests}. Type NUMBER. Provided by INVASION_UPDATED, INVASION_ENDED.

REMAINING_INVASION

RemainingInvasion. In text placeholders: ${param.remainingInvasion}. Type NUMBER. Provided by INVASION_UPDATED, INVASION_ENDED.

REMAINING_RESISTANCE

RemainingResistance. In text placeholders: ${param.remainingResistance}. Type NUMBER. Provided by INVASION_UPDATED, INVASION_ENDED.

CLEAR

Clear. In text placeholders: ${param.clear}. Type NUMBER. Provided by INVASION_UPDATED, INVASION_ENDED.

PREVIOUS

Previous. In text placeholders: ${param.previous}. Its type depends on the trigger: COUNTRY in COUNTRY_PUPPETED; COUNTRY_IDEOLOGY in IDEOLOGY_CHANGED; LEADER in LEADER_CHANGED; NUMBER in DIPLOMACY_STATUS_CHANGED.

VALUE

Value. In text placeholders: ${param.value}. Type NUMBER. Provided by DIPLOMACY_STATUS_CHANGED.

IDEOLOGY

Ideology. In text placeholders: ${param.ideology}. Type COUNTRY_IDEOLOGY. Provided by IDEOLOGY_CHANGED.

LEADER

Leader. In text placeholders: ${param.leader}. Type LEADER. Provided by LEADER_CHANGED.

NEXT_LEADER

NextLeader. In text placeholders: ${param.nextLeader}. Type LEADER. Provided by LEADER_CHANGED.

COALITION

Coalition. In text placeholders: ${param.coalition}. Type COALITION. Provided by GAME_ENDING.

Value types

ANY

Any type. Used by fields and parameters that accept every kind of value, such as a restart key. Values should declare their real type.

BOOLEAN

true or false. Constant: "true" or "false".

NUMBER

A decimal number. Constant: numeric text such as "12", "-0.5" or "1e6"; text that is not a number reads as 0.

STRING

Text. Text shown to players accepts placeholders and localized language maps (see textTemplate).

COLOR

An RGBA color. Constant: hexadecimal RRGGBB or RRGGBBAA (alpha last), with or without #, or the name of a skin color. Invalid text reads as white.

COUNTRY

A country. Constant: the country key (for example United_States_of_America), its numeric index, the code or name of a country in the scenario, null/none/water (no country) or uninhabitable.

COUNTRY_CLAIMS

Claims. Read from trigger parameters and methods; there is no constant form.

POINT

A map position, in cells. Constant: "x,y". Whole numbers select the center of a cell; decimals such as "120.25,90.75" select an exact position.

LAND_COVER

A land cover (terrain) type. Constant, case-insensitive: Broadleaf_Evergreen_Forest, Broadleaf_Deciduous_Forest, Needleleaf_Evergreen_Forest, Needleleaf_Deciduous_Forest, Mixed_Forest, Tree_Open, Shrub, Herbaceous, Herbaceous_with_Sparse_Tree__Shrub, Sparse_vegetation, Cropland, Paddy_field, Cropland__Other_Vegetation_Mosaic, Mangrove, Wetland, Bare_area_consolidated, Bare_area_unconsolidated, Urban, Snow__Ice, Water_bodies, Unnavigable, Wasteland, Sea_Ice.

SQUAD

A squad (army). Constant: the squad's numeric id, which only exists in a running game: squads normally come from trigger parameters, methods and queries.

SQUAD_TYPE

A squad type. Constant, case-insensitive: MILITIA, CONTROLLABLE, GUARD, TRAINABLE, ALL.

SQUAD_TASK

The kind of task a squad performs. Constant, case-insensitive: ATTACK, DEFEND, RETREAT, PATROL, GOTO, NONE.

AI_TYPE

An AI personality. Constant, case-insensitive: IMPERIALIST, AGGRESSIVE, DEFENSIVE, PEACEFUL.

UNIT

A unit type. Constant: the unit id.

TECHNOLOGY

A technology. Constant: the technology id.

RESEARCH

A research branch. Constant: the research id.

TECH_SCHOOL

A technology school. Constant, case-insensitive: MILITARY, ECONOMIC, SOCIAL.

AOE

An area effect. Constant: the area effect id.

AOE_TYPE

An area-effect operation. Constant, case-insensitive: ADD, PERCENT, NUCLEAR.

CUSTOM_EFFECT

An effect type, such as those created in the effects editor. Constant: the effect id.

CUSTOM_EFFECT_INSTANCE

An effect applied to a country, with its level. Read from methods; there is no constant form.

BONUS

Bonus. Read from trigger parameters and methods; there is no constant form.

BONUS_TYPE

A built-in bonus type. Constant, case-insensitive: RESEARCH_COST, EXCHANGE_RATE, GLOBAL_MARKET_ISOLATION, POPULATION_GROWTH, GDP_GROWTH, RESEARCH_GROWTH, MILITARY_GROWTH, MONEY_PRODUCTION, SOCIAL_EFFECT, GDP_EFFECT, BUDGET_ALLOCATION, INVESTMENT_YIELD, FINANCIAL_MICROMANAGEMENT, UNIT_POWER, UNIT_ATTACK, UNIT_PIERCING, UNIT_DEFENSE, UNIT_SPEED, UNIT_TIME, UNIT_COST, UNIT_CONSUMPTION, UNIT_SCALING, UNIT_COST_SCALING_HIGH, UNIT_COST_SCALING_LOW, UNIT_RESEARCH, CONSCRIPTION, PERSONNEL, TRAINING_PARALLELISM, BATTLE_HOME_ADVANTAGE, BATTLE_HOME_ADVANTAGE_DECAY, BATTLE_STAT_IMPACT, BATTLE_POWER_DIFFERENTIAL, CLAIM_DECAY, LOYALTY, LOYALTY_DECAY, MILITIA_SPAWN, MILITIA_SPAWN_DECAY, MILITIA_SPAWN_DECAY_FREEDOM, MILITIA_SPAWN_CLAIMS, DIPLOMACY_STRENGTH, DIPLOMACY_SPREAD, DIPLOMACY_SPREAD_FREEDOM, DIPLOMACY_ACTION_MONEY, COMBAT_EXPERIENCE, COMBAT_EXPERIENCE_DURATION, AMMUNITION_SHORTAGE, AMMUNITION_SHORTAGE_DURATION, MORALE, MORALE_DURATION, INTERNATIONAL_STANDING, INTERNATIONAL_STANDING_DURATION, PRESTIGE, IMMIGRATION, EMIGRATION, BATTLE_SELF_DEFENSE.

BONUS_ENTRY

Bonus. Read from trigger parameters and methods; there is no constant form.

TYPE_BONUS

Bonus entry. Read from trigger parameters and methods; there is no constant form.

COUNTRY_BONUS

Country bonus. Read from trigger parameters and methods; there is no constant form.

COUNTRY_TECH

A technology as researched by one country. Constant: "COUNTRY_INDEX:TECH_ID".

COUNTRY_RESEARCH

A research branch as progressed by one country. Constant: "COUNTRY_INDEX:RESEARCH_ID".

IDEOLOGY

An ideology. Constant: the ideology id. Accepted wherever COUNTRY_IDEOLOGY is, and the other way round.

COUNTRY_IDEOLOGY

An ideology as held by one country. Constant: "COUNTRY_INDEX:IDEOLOGY_ID".

IDEOLOGY_EFFECT

Ideology effect. Read from trigger parameters and methods; there is no constant form.

IDEOLOGY_PERK

Ideology perk. Read from trigger parameters and methods; there is no constant form.

IDEOLOGY_BONUS

Ideology bonus. Read from trigger parameters and methods; there is no constant form.

LEADER

A country leader. Normally read from trigger parameters and methods.

BATTLE

A battle between two squads. Constant: "SQUAD1_ID:SQUAD2_ID", which only exists in a running game.

INVASION

An invasion carried out by a squad. Constant: the invading squad's id.

DATE

A calendar date. Constant: YYYY-MM-DD.

GAME

The running game. Read it with the engine value game.

WORLD_ECONOMY

World economy totals. Read it with the engine value economy.

MAP

The world map. Read it with the engine value map.

MAP_REGIONS

Regions. Read from trigger parameters and methods; there is no constant form.

MAP_SUBREGIONS

Subregions. Read from trigger parameters and methods; there is no constant form.

MAP_CONTINENTS

Continents. Read from trigger parameters and methods; there is no constant form.

RNG

A random number generator.

REGISTRY

A registry: a saved key-value table written with SET_REGISTRY. Read it with a REGISTRY value.

RANKINGS

The world rankings. Read it with the engine value rankings.

COUNTRY_RANKINGS

Rankings. Read from trigger parameters and methods; there is no constant form.

COUNTRY_RANKING

Country ranking. Read from trigger parameters and methods; there is no constant form.

BUDGET

Budget. Read from trigger parameters and methods; there is no constant form.

COUNTRY_AI

Country AI. Read from trigger parameters and methods; there is no constant form.

COUNTRY_CALCULATIONS

Calculations. Read from trigger parameters and methods; there is no constant form.

RANKING

Ranking. Read from trigger parameters and methods; there is no constant form.

COALITION

A coalition of countries. Constant: its name or numeric index.

LIST

A list of items whose type is given by elementType. Only lists of points have a constant form, "x,y;x,y;..."; other lists come from methods, queries, registries and engine values.

GOAL_TYPE

A scenario goal. Constant, case-insensitive: GDP, POPULATION, AREA, MILITARY, POWER, NONE.

COUNTRY_OR_COALITION

Accepts a COUNTRY or a COALITION. Only used by command fields: a coalition applies the command to each of its current members.

Text and languages

Placeholders and localized text

Text shown to players: messages, map labels, HUD text and similar fields.

Placeholders are replaced when the action runs: ${var.NAME} for a local variable, ${shared.NAME} for a shared variable, ${param.NAME} for a trigger parameter and ${game.day} for the game day. A placeholder may continue with properties of the object it reads (for example ${param.country.name}), but arithmetic is not evaluated inside ${...}: compute the value first with SET_VARIABLE and insert the variable. ${expr:PAYLOAD} embeds an encoded expression; the editor produces it.

Localized text: instead of plain text, store a JSON language map serialized in the string, such as {"en":"Ready","es":"Listo"}. Players see their language, or English when it is missing, so always include en. Remember to escape the inner quotes.

Labels, messages and widgets keep the text from when the action ran; run the action again to refresh it.

Day ${game.day}
${var.leader} leads the world.
{"en":"Ready","es":"Listo"}

Animation timelines

Timeline format

Keyframe animation for map overlays and HUD elements. Each track animates one property over normalized time from 0 to 1; duration says how many seconds that takes. Playback uses the player's screen time, keeps going while the game is paused and is not synchronized between players. At most 65536 characters of JSON.

Running the same action again with the same timeline keeps the animation playing; a changed timeline (or motionKey) restarts it. The editor's Animation button offers presets, which are ordinary timelines;

FieldTypeRequiredDescription
durationnumberSeconds for one pass from time 0 to 1. Default: 1.
delaynumberSeconds hidden before playback starts. Default: 0.
speednumberPlayback speed multiplier. 0 holds the current phase. Default: 1.
phasenumberStarting position in the timeline, from 0 to 1. Default: 0.
loopone of the values belowDefault: "repeat".
clockone of the values belowDefault: "local".
endone of the values belowDefault: "hold".
pivotXnumberHorizontal center for scaling and rotation, as a fraction of the overlay's bounds (0 = left, 1 = right). Points, text and circles use their own anchors. Default: 0.5.
pivotYnumberVertical center for scaling and rotation, as a fraction of the overlay's bounds (0 = bottom, 1 = top). Default: 0.5.

Tracks and keyframes

Keyframes [time, value, easing?]. A single keyframe holds a constant value; before the first and after the last keyframe their values are held.

Keyframes [time, color, easing?] with RRGGBB or RRGGBBAA colors (an optional # is allowed). Channels are interpolated independently.

TrackValuesMeaning
scalenumberSize multiplier; circles scale around their own centers. Neutral value 1.
scaleXnumberAdditional size multiplier along one axis, combined with scale. Neutral value 1.
scaleYnumberAdditional size multiplier along one axis, combined with scale. Neutral value 1.
rotationnumberDegrees added to the rotation, counterclockwise. Neutral value 0.
offsetXnumberOffset in map cells along the map axis. Neutral value 0.
offsetYnumberOffset in map cells along the map axis. Neutral value 0.
screenXnumberOffset in screen pixels, positive right/up. Neutral value 0.
screenYnumberOffset in screen pixels, positive right/up. Neutral value 0.
opacitynumberOpacity of the whole overlay, including text backgrounds and shadows, from 0 to 1. Neutral value 1.
fillOpacitynumberOpacity of fills and of point/text glyphs, from 0 to 1. Neutral value 1.
outlineOpacitynumberOpacity of outlines, from 0 to 1. Neutral value 1.
widthnumberStroke width multiplier for paths and outlines. Neutral value 1.
colorcolorColor replacing the overlay's base color.
fillColorcolorFill and glyph color, overriding color.
outlineColorcolorOutline color, overriding color.
textureXnumberOffset added to a textured polygon's texture. Neutral value 0.
textureYnumberOffset added to a textured polygon's texture. Neutral value 0.
textureRotationnumberDegrees added to a textured polygon's texture rotation. Neutral value 0.
textureScalenumberMultiplier of a textured polygon's texture scale. Neutral value 1.

Easings

linear, smooth, smoother, easeIn, easeOut, easeInOut, cubicIn, cubicOut, cubicInOut, backOut, bounceOut, elasticOut, step.

[[0,1,"smooth"],[0.5,1.2,"smooth"],[1,1]]

Presets

The presets of the editor's Animation button. Each one is an ordinary timeline you can copy and change.

fadeIn
{"duration":0.6,"loop":"once","tracks":{"opacity":[[0,0,"smooth"],[1,1]]}}
fadeOut
{"duration":0.6,"loop":"once","end":"hide","tracks":{"opacity":[[0,1,"smooth"],[1,0]]}}
popIn
{"duration":0.45,"loop":"once","tracks":{"scale":[[0,0,"backOut"],[1,1]],"opacity":[[0,0],[0.3,1],[1,1]]}}
riseFade
{"duration":1,"loop":"once","end":"hide","tracks":{"scale":[[0,0.6,"backOut"],[0.3,1],[0.75,1,"easeIn"],[1,1.25]],"screenY":[[0,-26,"cubicOut"],[0.3,0],[0.75,0,"easeIn"],[1,44]],"opacity":[[0,0],[0.12,1],[0.75,1],[1,0]]}}
pulse
{"duration":1,"loop":"repeat","tracks":{"scale":[[0,1,"smooth"],[0.5,1.15,"smooth"],[1,1]]}}
ripple
{"duration":1.4,"loop":"repeat","tracks":{"scale":[[0,0.25,"easeOut"],[1,2.5]],"opacity":[[0,0],[0.08,1],[1,0]],"width":[[0,1.5],[1,0.5]]}}
bounce
{"duration":1,"loop":"repeat","tracks":{"screenY":[[0,28,"bounceOut"],[1,0]]}}
spin
{"duration":1,"loop":"repeat","tracks":{"rotation":[[0,0],[1,360]]}}
float
{"duration":2,"loop":"repeat","tracks":{"screenY":[[0,0,"smooth"],[0.25,10,"smooth"],[0.75,-10,"smooth"],[1,0]]}}
sway
{"duration":2.4,"loop":"repeat","tracks":{"rotation":[[0,-8,"smooth"],[0.5,8,"smooth"],[1,-8]]}}
shake
{"duration":0.5,"loop":"once","tracks":{"screenX":[[0,0],[0.12,-10],[0.28,8],[0.44,-6],[0.6,4],[0.78,-2],[1,0]]}}
orbit
{"duration":2.4,"loop":"repeat","tracks":{"screenX":[[0,14,"smooth"],[0.5,-14,"smooth"],[1,14]],"screenY":[[0,0,"easeOut"],[0.25,14,"easeInOut"],[0.75,-14,"easeIn"],[1,0]]}}
flash
{"duration":1,"loop":"repeat","tracks":{"opacity":[[0,0.15,"smooth"],[0.5,1,"smooth"],[1,0.15]]}}

Animating HUD elements

Animation of a HUD element: a timeline object, or the same object serialized as a string (empty disables it). HUD elements support only the tracks listed here; screen offsets use UI units.

Tracks: scale, scaleX, scaleY, rotation, screenX, screenY, opacity, color, fillColor, outlineColor, fillOpacity, outlineOpacity.

HUD widgets

Widget trees

Root element of a HUD widget, set with ui.widget_set. The root can also use anchor (screen position) and order. Limits: 64 widgets, 128 elements per widget, nesting depth 16 and 65536 characters per definition. Widgets and messages are saved with the game and stay until removed with ui.widget_remove or ui.widget_clear.

One element of a HUD widget. Property values are plain JSON values (numbers, strings, booleans), not Value nodes, except that any property except type, id and children can instead hold {"$value": Value}, an expression evaluated when ui.widget_set runs. Widgets do not refresh themselves: run ui.widget_update on a suitable trigger to change them.

{
  "type": "column",
  "anchor": "top_center",
  "gap": 4,
  "children": [
    {
      "type": "text",
      "id": "title",
      "text": {
        "en": "Readiness",
        "es": "Preparación"
      }
    },
    {
      "type": "bar",
      "id": "progress",
      "width": 220,
      "min": 0,
      "max": 100,
      "value": {
        "$value": {
          "kind": "CONSTANT",
          "type": "NUMBER",
          "value": "40"
        }
      }
    }
  ]
}

Element types

TypeMeaning
panelContainer with a background that holds children.
rowContainer that places children side by side.
columnContainer that stacks children vertically.
stackContainer that draws children on top of each other, for example text over a bar.
textA line or paragraph of text.
barA progress bar between min and max.
iconAn image.
spacerEmpty space, optionally with a background texture.

Child elements. Only panel, row, column and stack accept children.

Element properties

Which element types accept each property. "root only" properties apply to the widget's root element.

PropertyApplies toDescription
texttextText. Plain text with placeholders, or a localized language map.
iconiconIcon. Skin drawable name or embedded PNG. Default: RESOURCE_GDP.
scalingiconImage scaling. Default: fit.
valuebarValue. Default: 0.
minbarMinimum. Default: 0.
maxbarMaximum. Default: 1.
visibleallVisible. Default: true.
colortext, bar, iconColor. Default: ffffffff.
backgroundallBackground. Default: 15202eff.
stylepanel, row, column, stack, text, barStyle. Text styles: tiny, small, small-bold, default, bold, medium, medium-big, big, title. Bar styles: bar-default, bar-secondary, big-horizontal. Container styles: none, toolbar-default, window-default, plain, frame-round-secondary, frame-round-dim-secondary, list-secondary, dialog-secondary, tooltip-dark-secondary.
anchorroot onlyScreen anchor. Root only: the screen position of the widget. Default: top_center.
alignallContent alignment. Default: center.
xallHorizontal offset. Offset in UI units. Default: 0.
yallVertical offset. Offset in UI units. Default: 0.
widthallWidth. In UI units. Omit it to use the natural size. Default: 220.
heightallHeight. In UI units. Omit it to use the natural size. Default: 28.
widthFractionallRelative width. Fraction of the available parent or screen space. Default: 1.
heightFractionallRelative height. Fraction of the available parent or screen space. Default: 1.
paddingpanel, row, column, stackPadding. Default: 0.
gaprow, columnGap. Default: 4.
fontScaletextText size. Default: 1.
wraptextWrap text. Default: false.
orderroot onlyDisplay order. Root only: drawing order among widgets. Default: 0.
animationInallAppear animation. Default: none.
durationInallAppear duration (seconds). From 0 to 10 seconds. Default: 0.4.
animationOutallDisappear animation. Default: none.
durationOutallDisappear duration (seconds). From 0 to 10 seconds. Default: 0.4.
directionbarFill direction. Which way a bar fills. Default: right.
valueDurationbarValue transition (seconds). Seconds to animate value changes, from 0 to 10. Default: 0.
fillInsetbarFill inset. Default: 0.
skinStylepanel, row, column, stack, text, barCustom skin style. Optional name of a style in the skin or mod; missing names fall back to style.
backgroundTextureallBackground texture.
fillTexturebarFill texture.
borderTextureallFrame texture.
textureInsetallTexture slice inset. Nine-patch inset of embedded textures, in source pixels (0 to 128). Default: 0.
borderColorallOutline color. Default: ffffffff.
borderWidthallOutline width. Default: 0.
cornerRadiusallCorner radius. In UI units, from 0 to 128. Default: 0.
opacityallOpacity. Multiplies the opacity of the element and its children, from 0 to 1. Default: 1.
motionallAnimation. Keyframe animation; see hudMotion.
motionKeyallRestart value. Change it to restart the animation.
paddingLeftpanel, row, column, stackLeft padding. Default: 0.
paddingRightpanel, row, column, stackRight padding. Default: 0.
paddingToppanel, row, column, stackTop padding. Default: 0.
paddingBottompanel, row, column, stackBottom padding. Default: 0.

Expression bindings and images

An expression evaluated when the widget is set, used instead of a literal property value.

A skin drawable name, or an embedded PNG (at most 256x256 pixels and 48000 bytes).

{"type":"row","gap":6,"children":[{"type":"icon","id":"badge","icon":{"name":"my_badge","data":"BASE64_PNG_DATA"},"width":24,"height":24},{"type":"bar","id":"progress","width":180,"min":0,"max":1,"value":{"$value":{"kind":"CALL","type":"NUMBER","value":"country.progress","args":[{"kind":"GLOBAL","type":"COUNTRY","value":"player"}]}}}]}

Compact source

Compact source format

One or more scripts written as typed S-expressions, the format the game uses to save scripts. It maps one-to-one to the JSON tree but is much shorter.

Document

Document: (dscript 1 SCRIPT...). The (dscript 1 ...) wrapper with format version 1 is recommended; a plain sequence of (script ...) forms is also accepted. Whitespace is free, // starts a comment that runs to the end of the line, and atoms are either bare words without spaces or parentheses, or JSON-style quoted strings ("..." with \" \\ \n \t \uXXXX escapes). A lone - means "none" wherever an optional part is allowed.

Script

Script: (script ID ENABLED TRIGGER RUN_POLICY COOLDOWN_DAYS MAX_RUNS [DEFS] CONDITION ACTION...). ENABLED is 1/0 or true/false, RUN_POLICY is REPEAT or ONCE, and the two numbers are whole days and runs (0 = no limit).

Definitions

Definitions: (defs (NAME TYPE LITERAL)...) right after MAX_RUNS declares constants that the script reuses with (@ NAME) or (ref NAME), useful for long texts or point lists.

Types

Types are lowercase value type names (country, number, point...) plus the short forms bool, num, str, effect (CUSTOM_EFFECT), effect_instance (CUSTOM_EFFECT_INSTANCE), points (LIST of POINT) and list.TYPE for other lists.

Values

Values: (TYPE LITERAL) or (const TYPE LITERAL) for constants; (param TYPE NAME) for trigger parameters; (var TYPE NAME) for local variables; (shared TYPE NAME) for shared variables; (registry TYPE NAME) for registries; (engine TYPE ID) for engine values; (call TYPE METHOD_OR_FUNCTION_ID ARG...) for method and function calls; (query OPERATION VARIABLE COLLECTION CONDITION MAP) for collection queries, with - for an unused variable or map; (points "x,y;x,y") or (path64 PAYLOAD) for point lists, where path64 is an encoded form the game writes for long integer paths.

Conditions

Conditions: true; (? BOOLEAN_VALUE) to test a value; (! CONDITION) for NOT; (& CONDITION...) for AND, (| CONDITION...) for OR and (^ CONDITION...) for XOR; (every VARIABLE COLLECTION CONDITION...) and (any VARIABLE COLLECTION CONDITION...); (count VARIABLE COLLECTION TEST CONDITION...), where TEST is a BOOLEAN value that can read the local variable count. Any condition may end with (do ACTION...) setup statements, which run before it is evaluated.

Actions

Actions: (noop); (patch TEXT); (message TEXT), (warn TEXT) and (alert TEXT); (let NAME VALUE) for a local variable; (global NAME VALUE) for a shared variable; (store OPERATION REGISTRY KEY VALUE) with set, append, remove or clear; (if CONDITION ACTION...); (each VARIABLE COLLECTION ACTION...); and (cmd COMMAND_ID ENTRY...).

Command entries

Command entries: (arg FIELD VALUE) for each field; (land KIND VALUE SOURCE OWNER_FILTER) for land selections, using - for parts that are not needed; (stroke X Y SIZE HARDNESS NOISE OPERATION VALUE MIDDLE WEAK) for the paint strokes of map.paint_* commands.

Match data

(match-data ID INDEX) is reserved for values that servers supply to online matches.

Errors and replacement

Loading reports errors with their line and column. Each script fully replaces the script with the same id; its run count and cooldown are kept.

Examples

(dscript 1 (script welcome 1 GAME_STARTED ONCE 0 1 true (message "Welcome to the scenario.")))
(dscript 1
  // Reward large countries once a month.
  (script reward_growth 1 COUNTRY_DAILY_UPDATE REPEAT 30 0
    (? (call bool number.greater_equal (call num country.population (param country COUNTRY)) (num 50000000)))
    (cmd country.modify_data (arg country (param country COUNTRY)) (arg field (str money)) (arg operation (str ADD)) (arg amount (num 1000)))))
(dscript 1 (script route 1 GAME_STARTED ONCE 0 1 true (cmd map.render_path (arg path (points "120,90;160,105;220,92")) (arg width (num 3)) (arg color (color ffffffc0)) (arg mode (str geometry)) (arg smooth (bool true)))))

Saved state

Runtime state

Run counts, shared variables and registries saved during a game.

FieldTypeRequiredDescription
scriptRunslist of object
globalslist of objectShared variables.
registrieslist of object