Wiki

effect · clr_state_flag

Definition

  • Supported scope:STATE
  • Supported target:none

Description

clear state flag

实战 · 配合 · 坑

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

实战用法

clr_state_flag 用于在完成某个阶段性任务后清除之前通过 set_state_flag 设置的标记,从而重置状态机或允许事件/决议再次触发。典型场景包括:清除用于追踪建设进度的临时标记、在地区占领状态改变后重置相关流程标记。

# 当地区被完全控制后,清除建设中的临时 flag,允许下一阶段决议再次显示
state_event = {
    id = my_mod.101
    ...
    option = {
        name = my_mod.101.a
        clr_state_flag = region_under_construction
    }
}

配合关系

  • [has_state_flag](/wiki/trigger/has_state_flag):在清除前先用此触发器检查 flag 是否存在,避免逻辑冲突或重复清除。
  • [set_state_flag](/wiki/effect/set_state_flag):两者组成完整的 flag 生命周期管理,一个设置、一个回收,是状态机设计的标准搭档。
  • [modify_state_flag](/wiki/effect/modify_state_flag):若需要的不是清除而是修改数值型 flag,可与 clr_state_flag 配合形成"重置后重设"的模式。
  • [state_event](/wiki/effect/state_event):清除 flag 后常立即触发一个新事件来推进剧情或任务流程的下一阶段。

常见坑

  1. Scope 用错clr_state_flag 只能在 STATE scope 下执行,若在国家或省份 scope 中调用会静默失败且不报错,新手容易因 scope 嵌套层级混乱而写错位置,需仔细核查外层 scope 是否已切换到地区。
  2. 清除不存在的 flag 不报错但逻辑隐患大:游戏不会因为清除一个从未设置过的 flag 而报错,但若依赖该 flag 的触发器判断在清除前已经被其他逻辑提前走完,会导致状态机跳过预期步骤,建议始终搭配 [has_state_flag](/wiki/trigger/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

clr_state_flag is used to clear flags previously set via set_state_flag after completing a specific task phase, allowing you to reset state machines or enable events/decisions to trigger again. Typical scenarios include: clearing temporary flags used to track construction progress, resetting related workflow flags after a region's control status changes.

# When a region is fully controlled, clear the temporary construction flag to allow the next-phase decision to appear again
state_event = {
    id = my_mod.101
    ...
    option = {
        name = my_mod.101.a
        clr_state_flag = region_under_construction
    }
}

Synergy

  • [has_state_flag](/wiki/trigger/has_state_flag): Use this trigger to check if the flag exists before clearing it, avoiding logic conflicts or duplicate clears.
  • [set_state_flag](/wiki/effect/set_state_flag): The two form a complete flag lifecycle management system—one sets, one clears—and are the standard pairing for state machine design.
  • [modify_state_flag](/wiki/effect/modify_state_flag): If you need to modify a numeric flag rather than clear it outright, you can combine it with clr_state_flag to create a "reset-then-reinitialize" pattern.
  • [state_event](/wiki/effect/state_event): Clearing a flag often immediately triggers a new event to advance the narrative or task flow to the next phase.

Common Pitfalls

  1. Wrong scope: clr_state_flag can only execute in STATE scope. Calling it within a country or province scope will fail silently without error messages. Beginners often make this mistake due to confused scope nesting levels—carefully verify that the outer scope has already switched to the state.
  2. Clearing non-existent flags produces no error but creates logic hazards: The game won't error if you clear a flag that was never set, but if a trigger depending on that flag completes its check before the clear due to other logic running first, the state machine will skip expected steps. Always pair with [has_state_flag](/wiki/trigger/has_state_flag) for pre-clearing validation.