effect · modify_global_flag
Definition
- Supported scope:
any - Supported target:
none
Description
modify global flag. Only modifies if flag already exists.
Example: modify_global_flag = { flag = <name> value = <number> }
modify_global_flaganynonemodify global flag. Only modifies if flag already exists.
Example: modify_global_flag = { flag = <name> value = <number> }
Hands-on notes are AI-generated and checked against the vanilla command vocabulary — treat them as a starting point, not authoritative reference. The definition above is the game's own documentation.
modify_global_flag is commonly used in mod scenarios where you need to increment or decrement an existing global counter, such as tracking the number of times a global event fires, war intensity scores, or diplomatic prestige values. Unlike direct overwriting, it avoids unexpected initialization when the flag's existence is uncertain, making it ideal for designs where multiple countries write to the same global state.
# Each time a certain country triggers an event, increment the global war intensity counter by 1
country_event = {
id = my_mod.10
option = {
name = my_mod.10.a
modify_global_flag = {
flag = global_war_intensity
value = 1
}
}
}
[set_global_flag](/wiki/effect/set_global_flag): Used to initialize a global flag and assign an initial value. Since modify_global_flag only modifies existing flags, you must first create it with set_global_flag.[has_global_flag](/wiki/trigger/has_global_flag): Check whether a flag exists and its value range in trigger conditions, forming a "read-write" pairing with modify_global_flag.[clr_global_flag](/wiki/effect/clr_global_flag): Clear the flag at the end of a global process, completing the "initialize → accumulate → clear" lifecycle together with set_global_flag and modify_global_flag.[if](/wiki/effect/if): Wrap the modification logic with a has_global_flag condition before modifying to ensure execution only when the flag truly exists, avoiding silent failures that are difficult to debug.set_global_flag beforehand, execution produces no error but also has no effect, making logic difficult to debug.value: value is an increment (which can be negative) on top of the existing value, not an absolute assignment. If you want to directly assign a value, use set_global_flag = { flag = ... value = ... } instead. Confusing the two causes continuous value drift.