Hands-On Usage
add_dynamic_modifier is commonly used in scenarios where modifier values need to be dynamically adjusted based on variables, such as scaling bonuses/penalties in real-time according to a country's industrial capacity or resource levels, or applying temporary debuffs to specific countries or states (e.g., war damage, blockade penalties). Its core difference from static modifiers like add_state_modifier / add_ideas is that the modifier's numerical values come from variables and change in real-time as the game progresses.
# Add a dynamic modifier to Germany lasting 60 days, bound to the GER scope
42 = {
add_dynamic_modifier = {
modifier = war_damage_modifier
scope = GER
days = 60
}
}
Synergy
[remove_dynamic_modifier](/wiki/effect/remove_dynamic_modifier): After adding a dynamic modifier, remove it when conditions are met, forming a complete lifecycle management of "add → condition trigger → remove".
[force_update_dynamic_modifier](/wiki/effect/force_update_dynamic_modifier): When the bound variable changes within a tick, force the dynamic modifier to refresh its actual numerical value, preventing display or calculation lag.
[has_dynamic_modifier](/wiki/trigger/has_dynamic_modifier): Check in a trigger whether a scope already possesses the dynamic modifier, preventing accidental stacking or used for branching logic.
[add_days_remove](/wiki/effect/add_days_remove): If you need to temporarily extend the duration of an existing dynamic modifier in an event or decision, use this in combination to modify the countdown.
Common Pitfalls
- Forgetting the
scope field causes the modifier to apply to the wrong target: When called under a state (STATE) scope without specifying scope, the modifier affects all countries that own that state; if you only want it to affect a specific country, you must explicitly write scope = TAG, otherwise the modifier may unexpectedly spread to other countries.
- Adding a dynamic modifier when its variable is not initialized: If the variable that a dynamic modifier depends on has not been assigned a value when the modifier is added (is 0 or doesn't exist), the modifier will calculate with a default value of 0, appearing to have "no effect". Beginners often mistakenly think the script is wrong, but you should ensure that the corresponding variable is initialized with a value via
set_variable or related effects before calling add_dynamic_modifier.