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> }
实战内容由 AI 生成,并已对照 vanilla 命令词表校验 —— 请当作起点而非权威依据。上方的定义节才是游戏自带文档原文。
modify_global_flag 常用于需要对已有全局计数器进行累加或递减的 mod 场景,例如追踪全局事件触发次数、战争烈度积分或外交声望值。与直接覆盖不同,它在不确定旗帜是否存在时能避免意外初始化,适合多国事件共同写入同一全局状态的设计。
# 每次某国触发事件时,全局战争烈度计数器 +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):用于初始化全局旗帜并赋予初始数值,因为 modify_global_flag 只修改已存在的旗帜,必须先用 set_global_flag 创建它。[has_global_flag](/wiki/trigger/has_global_flag):在触发条件中检查旗帜是否存在及其数值范围,与 modify_global_flag 形成"读-写"配合。[clr_global_flag](/wiki/effect/clr_global_flag):在全局流程结束时清除旗帜,与 set_global_flag / modify_global_flag 共同组成"初始化→累积→清除"的完整生命周期。[if](/wiki/effect/if):在修改前先用 has_global_flag 条件包裹,确保只在旗帜确实存在时执行修改逻辑,避免静默失效难以排查。set_global_flag 初始化,执行后不会报错但也不会有任何效果,导致逻辑难以调试。value 是在原有数值基础上的增量(可为负数),而非设置绝对值;若想直接赋值应改用 set_global_flag = { flag = ... value = ... },混淆二者会导致数值持续偏移。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.