Wiki

effect · add_scientist_trait

Definition

  • Supported scope:CHARACTER
  • Supported target:none

Description

Add a trait to a scientist character in scope.
	ex: my_character = {
	  add_scientist_trait = my_trait_token
	}

实战 · 配合 · 坑

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

实战用法

add_scientist_trait 常用于 mod 中为自定义科学家角色在初始化时赋予专属特质,或在特定事件触发后动态解锁新特质(例如完成某研究项目后奖励科学家"突破性发现"类特质)。注意该命令必须在 CHARACTER scope 下调用,通常配合国家事件或焦点完成的 hidden_effect 块使用。

# 某焦点完成后,为指定科学家角色添加特质
focus = {
    id = my_focus_boost_scientist
    ...
    completion_reward = {
        my_scientist_character = {
            add_scientist_trait = my_breakthrough_trait
        }
    }
}

配合关系

  • [add_scientist_role](/wiki/effect/add_scientist_role):在赋予特质之前,先确保角色已拥有科学家职位,否则特质可能无法生效或无意义。
  • [add_scientist_level](/wiki/effect/add_scientist_level):常与添加特质同步使用,一并提升科学家等级以体现成长奖励的完整性。
  • [has_trait](/wiki/trigger/has_trait):在条件块中检查角色是否已拥有某特质,避免重复添加同一特质造成逻辑错误。
  • [is_active_scientist](/wiki/trigger/is_active_scientist):添加特质前用于校验该角色当前是否处于活跃科学家状态,确保操作对象合法。

常见坑

  1. Scope 错误:直接在 COUNTRY scope 下调用 add_scientist_trait 而不先通过角色变量进入 CHARACTER scope,会导致脚本报错或静默失败——务必用 my_character = { ... } 形式切换到角色本身的 scope 再执行。
  2. 特质 token 未注册:填写的特质 token 必须已在 scientist_traits 相关定义文件中声明,直接填写未定义的字符串不会报错提示但完全不会生效,调试时容易被忽略。

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

add_scientist_trait is commonly used in mods to assign exclusive traits to custom scientist characters during initialization, or to dynamically unlock new traits after specific events trigger (for example, rewarding a scientist with a "breakthrough discovery" trait upon completing a research project). Note that this command must be called within CHARACTER scope, typically used together with hidden_effect blocks in national events or focus completion rewards.

# After a focus completes, add a trait to the designated scientist character
focus = {
    id = my_focus_boost_scientist
    ...
    completion_reward = {
        my_scientist_character = {
            add_scientist_trait = my_breakthrough_trait
        }
    }
}

Synergy

  • [add_scientist_role](/wiki/effect/add_scientist_role): Before assigning a trait, ensure the character already holds a scientist position, otherwise the trait may fail to take effect or be meaningless.
  • [add_scientist_level](/wiki/effect/add_scientist_level): Commonly used in tandem with trait addition to simultaneously raise the scientist's level, reflecting the completeness of the growth reward.
  • [has_trait](/wiki/trigger/has_trait): Check in condition blocks whether the character already possesses a certain trait, avoiding duplicate additions of the same trait that cause logic errors.
  • [is_active_scientist](/wiki/trigger/is_active_scientist): Use before adding a trait to verify whether the character is currently in an active scientist status, ensuring the operation target is valid.

Common Pitfalls

  1. Scope Error: Calling add_scientist_trait directly in COUNTRY scope without first entering CHARACTER scope through a character variable will result in script errors or silent failures—be sure to switch to the character's own scope using the my_character = { ... } form before executing.
  2. Trait Token Not Registered: The trait token you specify must already be declared in the scientist_traits related definition files. Typing an undefined string will not produce an error message but will have no effect whatsoever, easily overlooked during debugging.