Wiki

effect · set_state_flag

Definition

  • Supported scope:STATE
  • Supported target:none

Description

set state flag

实战 · 配合 · 坑

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

实战用法

set_state_flag 常用于在事件链或决策中为特定地区打上"已处理"标记,防止同一效果被重复触发,或用来追踪某省份的特殊剧情状态(如"已被开发""起义已爆发"等)。典型场景是在占领/解放事件中标记该地区已完成初始化流程。

# 在某决策的 complete_effect 中,标记该州已完成工业开发
complete_effect = {
    FROM = {  # FROM 为目标 STATE scope
        set_state_flag = industrial_developed
        add_building_construction = {
            type = industrial_complex
            level = 1
            instant_build = yes
        }
    }
}

配合关系

  • [has_state_flag](/wiki/trigger/has_state_flag):最直接的搭档,用于在 trigger 块中检测该 flag 是否已被设置,从而实现"只执行一次"逻辑。
  • [clr_state_flag](/wiki/effect/clr_state_flag):清除已设置的 flag,两者配合可构成"开关"状态机,动态切换地区的特殊标记。
  • [modify_state_flag](/wiki/effect/modify_state_flag):在需要对 flag 附加数值(计数器)时与 set_state_flag 配合使用,先 set 初始化,再 modify 累加。
  • [state_event](/wiki/effect/state_event):常在 flag 被设置后立即触发地区事件,将标记行为与事件链串联起来。

常见坑

  1. Scope 写错位置set_state_flag 必须在 STATE scope 下执行,若在 COUNTRY scope 的 effect 块中直接写会报错;需要用 capital_scope 或显式指定某个州的 scope 进入后再调用。
  2. Flag 名拼写不一致:flag 名是纯字符串匹配,set_state_flag = my_Flaghas_state_flag = my_flag 因大小写不同会永远判定为 false,建议全程使用小写加下划线的统一命名规范。

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

set_state_flag is commonly used in event chains or decisions to mark a specific region as "processed," preventing the same effect from being triggered repeatedly, or to track special narrative states of a province (such as "has been developed" or "uprising has occurred"). A typical scenario is marking that region's initialization process as complete during occupation or liberation events.

# In the complete_effect of a decision, mark the state as having completed industrial development
complete_effect = {
    FROM = {  # FROM is the target STATE scope
        set_state_flag = industrial_developed
        add_building_construction = {
            type = industrial_complex
            level = 1
            instant_build = yes
        }
    }
}

Synergy

  • [has_state_flag](/wiki/trigger/has_state_flag): The most direct counterpart, used in trigger blocks to check whether the flag has been set, enabling "execute only once" logic.
  • [clr_state_flag](/wiki/effect/clr_state_flag): Clears a set flag; the two together form a state machine "switch" that dynamically toggles special markings for a region.
  • [modify_state_flag](/wiki/effect/modify_state_flag): When you need to attach numeric values (counters) to a flag, use it alongside set_state_flag—first set to initialize, then modify to accumulate.
  • [state_event](/wiki/effect/state_event): Commonly triggers a region event immediately after a flag is set, linking the marking behavior with the event chain.

Common Pitfalls

  1. Scope in wrong location: set_state_flag must be executed under STATE scope; calling it directly in a COUNTRY scope's effect block will cause an error. You need to use capital_scope or explicitly enter a specific state's scope before calling it.
  2. Flag name spelling inconsistency: Flag names are matched as plain strings, so set_state_flag = my_Flag and has_state_flag = my_flag will always evaluate as false due to case differences. It is recommended to use a consistent naming convention of lowercase with underscores throughout.