Save a number on a kingdom
Save a number on a kingdom
Section titled “Save a number on a kingdom”Store an integer owned by your addon on a Kingdom, then read it back later.
This recipe assumes your Political World addon is already registered.
Where this code goes
Section titled “Where this code goes”This snippet is not a complete mod by itself. Put it inside code that already has a real Kingdom kingdom, for example an event callback, action handler or another feature method. If you do not have a kingdom object yet, solve that first instead of inventing one.
Minimal code
Section titled “Minimal code”const string AddonId = "Example.MyAddon";const string Key = "reputation";
int current = PoliticalWorldAPI.GetKingdomInt( kingdom, AddonId, Key, 0);
bool written = PoliticalWorldAPI.SetKingdomInt( kingdom, AddonId, Key, current + 1);0 is the fallback returned when the value does not exist yet.
Expected result
Section titled “Expected result”On the tested stack, kingdom addon int data survived:
immediate readsame-save reloadfull WorldBox process restartWBML also verified tested cross-world isolation for kingdom addon state.
Common mistake
Section titled “Common mistake”Do not invent Political World’s internal save key yourself. Use the public GetKingdom* / SetKingdom* methods so addon ID and local key remain namespaced correctly.
Need another type?
Section titled “Need another type?”The same public family exists for:
stringboolfloatOpen the full addon-private kingdom data reference for exact behavior, storage notes and limits.