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”Register one reusable action that can only run for a valid kingdom and increments addon state.
Where this code goes
Section titled “Where this code goes”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 ); } });Check before execution
Section titled “Check before execution”bool allowed = PoliticalWorldAPI.CanExecuteAction(ActionId, kingdom);Then execute only when your flow actually wants the action to happen.
Important trap: same ID is replacement
Section titled “Important trap: same ID is replacement”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.
Cleanup
Section titled “Cleanup”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.