Wiki

effect · modify_character_flag

Definition

  • Supported scope:CHARACTER
  • Supported target:none

Description

modify character flag. Only modifies if flag already exists.
Example: _modify_character_flag_ = { flag = <name> value = <number> }

实战 · 配合 · 坑

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

实战用法

modify_character_flag 常用于需要对角色进行计数或累积追踪的场景,例如记录某角色执行某项任务的次数、累积受伤次数或积累特定行为点数,配合后续 trigger 判断达到阈值时触发特殊事件或解锁特质。注意该指令只能修改已存在的 flag,因此通常需要先在角色初始化阶段用 set_character_flag 创建带初始值的 flag,之后再用本指令对其进行数值增减。

# 每次角色参与某事件,计数 flag +1
character_event = {
    id = my_mod.10
    hidden = yes
    immediate = {
        # 假设 "battle_count" flag 已在角色创建时初始化
        modify_character_flag = {
            flag = battle_count
            value = 1
        }
    }
}

配合关系

  • [set_character_flag](/wiki/effect/set_character_flag):在使用 modify_character_flag 之前必须先用此命令创建并设定 flag 的初始值,否则本指令不会生效。
  • [has_character_flag](/wiki/trigger/has_character_flag):用于检查 flag 是否存在及其当前数值是否达到阈值,是触发后续逻辑(如解锁特质、触发事件)的必要判断条件。
  • [clr_character_flag](/wiki/effect/clr_character_flag):当计数达到目标值完成某阶段逻辑后,用于重置或清除该 flag,避免数值无限累积产生意外行为。
  • [add_trait](/wiki/effect/add_trait):常作为计数达标后的奖励结果,与 has_character_flag 的阈值判断配合,在满足条件时为角色添加对应特质。

常见坑

  1. flag 不存在时静默失效:新手最常见的错误是直接使用 modify_character_flag 而忘记预先用 set_character_flag 初始化该 flag,由于游戏不会报错只会静默跳过,导致计数逻辑完全不生效且极难排查。
  2. scope 指向错误:该指令必须在 CHARACTER scope 下执行,若在 COUNTRY 或其他 scope 中调用而未通过 character = { ... } 等方式正确切换作用域,同样会静默失败。

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

modify_character_flag is commonly used in scenarios requiring counting or cumulative tracking of character actions, such as recording the number of times a character completes a task, accumulating injury counts, or building up specific behavior points. Combined with subsequent trigger checks against thresholds, it can trigger special events or unlock traits. Note that this command can only modify existing flags; therefore, you typically need to first initialize the flag with an initial value using set_character_flag during the character setup phase, and then use this command to increment or decrement its value.

# Increment the count flag by 1 each time the character participates in an event
character_event = {
    id = my_mod.10
    hidden = yes
    immediate = {
        # Assume the "battle_count" flag has already been initialized when the character was created
        modify_character_flag = {
            flag = battle_count
            value = 1
        }
    }
}

Synergy

  • [set_character_flag](/wiki/effect/set_character_flag): Must be used before modify_character_flag to create the flag and set its initial value; otherwise, this command will have no effect.
  • [has_character_flag](/wiki/trigger/has_character_flag): Used to check whether a flag exists and whether its current value meets the threshold—an essential condition for triggering subsequent logic (such as unlocking traits or triggering events).
  • [clr_character_flag](/wiki/effect/clr_character_flag): Used to reset or clear the flag after the count reaches the target value and completes a stage of logic, preventing infinite accumulation and unexpected behavior.
  • [add_trait](/wiki/effect/add_trait): Often serves as the reward result after the count threshold is met; combined with the threshold check of has_character_flag, it adds the corresponding trait to the character when conditions are satisfied.

Common Pitfalls

  1. Silent failure when flag doesn't exist: The most common beginner mistake is using modify_character_flag directly without first initializing the flag with set_character_flag. Since the game will silently skip without reporting an error, the counting logic fails entirely and is extremely difficult to debug.
  2. Incorrect scope targeting: This command must be executed within CHARACTER scope. If called from COUNTRY or other scopes without properly switching the scope via character = { ... } or similar mechanisms, it will likewise fail silently.