Wiki

trigger · has_state_flag

Definition

  • Supported scope:STATE
  • Supported target:any

Description

has state flag been setCheck flag val date set and days since set.
Example: has_state_flag = test_flag
has_state_flag = { 
	flag = <name> (mandatory)
	value < <int> (optional)
	date > <date> (optional)
	days > <int> (optional)
}

实战 · 配合 · 坑

实战内容由 AI 生成,并已对照 vanilla 命令词表校验 —— 请当作起点而非权威依据。上方的定义节才是游戏自带文档原文。

实战用法

has_state_flag 常用于追踪某地区是否已触发过特定事件或完成过特定操作,例如判断某州是否已经历过"叛乱爆发"或"重建完成"等自定义阶段标记。在抵抗运动、占领事件链或区域发展 mod 中尤为常见,可配合可选参数精确控制标志的值范围或存续时间。

# 仅当该州已被标记为"重建完成"且标记设置超过 30 天后,才允许触发下一阶段事件
available = {
    has_state_flag = {
        flag = reconstruction_done
        days > 30
    }
}

配合关系

  • [set_state_flag](/wiki/effect/set_state_flag):最直接的配对关系,先用 set_state_flag 写入标志,再用 has_state_flag 在后续条件中读取,构成"写→读"闭环。
  • [clr_state_flag](/wiki/effect/clr_state_flag):在条件满足并执行完相应逻辑后,调用 clr_state_flag 清除标志,防止同一事件链重复触发。
  • [modify_state_flag](/wiki/effect/modify_state_flag):当需要对标志做累计计数(value 递增)时,配合 has_state_flagvalue < 参数检测当前计数阈值,实现多阶段进度追踪。
  • [has_dynamic_modifier](/wiki/trigger/has_dynamic_modifier):两者常同时出现在同一 limit 块中,共同约束某个动态修正器只在特定旗帜与动态修正器同时存在时才生效。

常见坑

  1. Scope 写错位置has_state_flag 必须在 STATE scope 下调用,新手有时在 COUNTRY scope 的 limit 中直接写该 trigger,导致脚本报错或永远返回假——需要先用 any_neighbor_state / capital_scope 等切换到 STATE scope 再判断。
  2. 忽略标志未被设置时的默认行为:如果对应标志从未被 set_state_flag 写入,has_state_flag 直接返回假而不会报错,容易让开发者误以为条件逻辑正确,实则标志名拼写错误(大小写或下划线不一致)导致标志始终不存在。

Hands-On Notes

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.

Hands-On Usage

has_state_flag is commonly used to track whether a specific region has triggered a particular event or completed a specific action, such as determining whether a state has experienced a custom milestone like "rebellion outbreak" or "reconstruction complete". It is especially prevalent in resistance movement, occupation event chains, or regional development mods, and can be combined with optional parameters to precisely control the flag's value range or duration.

# Only allow the next phase event to trigger after this state is marked as "reconstruction complete" and the flag has been set for more than 30 days
available = {
    has_state_flag = {
        flag = reconstruction_done
        days > 30
    }
}

Synergy

  • [set_state_flag](/wiki/effect/set_state_flag): The most direct pairing—use set_state_flag to write the flag first, then use has_state_flag in subsequent conditions to read it, forming a "write→read" loop.
  • [clr_state_flag](/wiki/effect/clr_state_flag): After conditions are met and corresponding logic is executed, call clr_state_flag to clear the flag, preventing duplicate triggers in the same event chain.
  • [modify_state_flag](/wiki/effect/modify_state_flag): When cumulative counting of a flag is needed (incrementing value), combine it with has_state_flag's value < parameter to detect the current count threshold, enabling multi-stage progress tracking.
  • [has_dynamic_modifier](/wiki/trigger/has_dynamic_modifier): Both often appear simultaneously in the same limit block, jointly constraining a dynamic modifier to only take effect when both the specific flag and dynamic modifier exist concurrently.

Common Pitfalls

  1. Wrong scope placement: has_state_flag must be called within STATE scope. Beginners sometimes write this trigger directly in a limit block under COUNTRY scope, causing script errors or always returning false—use any_neighbor_state / capital_scope and similar commands to switch to STATE scope first before checking.
  2. Overlooking default behavior when flag is never set: If the corresponding flag is never written by set_state_flag, has_state_flag simply returns false without error, easily misleading developers into thinking the condition logic is correct when actually the flag name has a typo (case or underscore mismatch), so the flag never exists.