Skip to content

Create a Political World action with a condition

Create a Political World action with a condition

Section titled “Create a Political World action with a condition”
✅ Runtime verified — executed branchesWBML-0005PoliticalWorldAPI 1.14.0

Register one reusable action that can only run for a valid kingdom and increments addon state.

Register the action once from your addon initialization flow after your Political World addon registration is available. The action Handler receives the Kingdom later when the action is executed, so you do not need to fabricate a kingdom during registration.

private const string AddonId = "Example.Actions";
private const string ActionId = AddonId + ".increase_counter";
PoliticalWorldAPI.RegisterAction(
AddonId,
new PoliticalWorldAPI.ActionDefinition
{
Id = ActionId,
Category = "example",
DisplayName = "Increase counter",
Condition = kingdom => kingdom != null,
Handler = kingdom =>
{
int current = PoliticalWorldAPI.GetKingdomInt(
kingdom,
AddonId,
"counter",
0
);
PoliticalWorldAPI.SetKingdomInt(
kingdom,
AddonId,
"counter",
current + 1
);
}
}
);
bool allowed = PoliticalWorldAPI.CanExecuteAction(ActionId, kingdom);

Then execute only when your flow actually wants the action to happen.

On runtime API 1.14.0, a second RegisterAction with the same ID replaced the previous definition instead of being rejected as a duplicate.

That means an accidental repeated ID can replace metadata, condition or handler.

If the action is temporary, unregister it when appropriate. WBML-0005 verified unregister and post-unregister lookup/execution behavior.

Open Actions / Conditions / Effects for validation codes, combinators, TryExecuteAction, Effects.Sequence and the party-support edge case.