Wiki

effect · set_character_name

Definition

  • Supported scope:COUNTRY, CHARACTER
  • Supported target:none

Description

"set name for the target character. Either localization key or direct name.
example:
set_character_name = {
	character = my_character # optional, use if not in a character scope
	name = my_name # either loc key or direct name
}
my_character = {
	set_character_name = my_name # only possible in character scope
}

实战 · 配合 · 坑

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

实战用法

set_character_name 常用于动态叙事场景,例如角色经历特定事件后获得新称号、化名或头衔(如地下领袖在暴露后改名换姓,或君主加冕后正式更名)。在国家 scope 下需要通过 character = 字段指定目标角色;在角色 scope 下可直接传入名字字符串,写法更简洁。

# 在国家 scope 下,通过事件为特定角色改名
country_event = {
    id = my_mod.10
    option = {
        name = my_mod.10.a
        # 使用本地化键,支持多语言
        set_character_name = {
            character = GER_my_spy
            name = GER_my_spy_alias
        }
    }
}

# 在角色 scope 下直接赋名(例如 on_action 触发)
GER_my_spy = {
    set_character_name = "Heinrich Braun"
}

配合关系

  • [set_portraits](/wiki/effect/set_portraits) — 角色改名时往往意味着形象也需要同步替换(如乔装或身份转变),两者常同时调用以保持视觉一致性。
  • [set_nationality](/wiki/effect/set_nationality) — 当角色叛逃或流亡时,名字和国籍通常一并变更,配合使用可完整表达身份切换。
  • [add_country_leader_trait](/wiki/effect/add_country_leader_trait) / [remove_country_leader_trait](/wiki/effect/remove_country_leader_trait) — 重命名后常伴随特质的增删,用于强化叙事上角色"蜕变"的感觉。
  • [has_character_flag](/wiki/trigger/has_character_flag) — 用于检查是否已触发过改名,避免同一角色被重复命名导致逻辑混乱。

常见坑

  1. 在国家 scope 下忘写 character = 字段:直接写 set_character_name = my_name 在国家 scope 下是无效语法,必须用花括号形式并指定 character = ...,否则游戏会静默报错或无任何效果。
  2. 混淆本地化键与直接字符串:传入的 name 既可以是本地化键(在 .yml 文件中定义),也可以是带引号的直接字符串;若未加引号且本地化文件中又找不到该键,角色名将显示为原始键名文本,而非预期内容,需注意区分使用场景。

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_character_name is commonly used in dynamic narrative scenarios, such as when a character acquires a new title, alias, or epithet after experiencing a specific event (for example, an underground leader changing identity after exposure, or a monarch formally renaming themselves upon coronation). Within a country scope, the target character must be specified via the character = field; within a character scope, you can pass the name string directly for more concise syntax.

# Within country scope, rename a specific character via event
country_event = {
    id = my_mod.10
    option = {
        name = my_mod.10.a
        # Use localization keys to support multiple languages
        set_character_name = {
            character = GER_my_spy
            name = GER_my_spy_alias
        }
    }
}

# Directly assign name within character scope (e.g., triggered by on_action)
GER_my_spy = {
    set_character_name = "Heinrich Braun"
}

Synergy

  • [set_portraits](/wiki/effect/set_portraits) — When renaming a character, their appearance typically needs to be updated simultaneously (such as disguises or identity changes); both are often called together to maintain visual consistency.
  • [set_nationality](/wiki/effect/set_nationality) — When a character defects or goes into exile, name and nationality are usually changed in tandem; using them together fully expresses an identity transition.
  • [add_country_leader_trait](/wiki/effect/add_country_leader_trait) / [remove_country_leader_trait](/wiki/effect/remove_country_leader_trait) — Renaming is frequently accompanied by adding or removing traits to reinforce the narrative sense of character "transformation."
  • [has_character_flag](/wiki/trigger/has_character_flag) — Used to check whether a rename has already been triggered, preventing the same character from being renamed repeatedly and causing logical conflicts.

Common Pitfalls

  1. Forgetting the character = field within country scope: Writing set_character_name = my_name directly in country scope is invalid syntax; you must use the curly brace form and specify character = .... Otherwise, the game will silently error or have no effect.
  2. Confusing localization keys with direct strings: The name parameter can be either a localization key (defined in a .yml file) or a quoted direct string. If not quoted and the key cannot be found in the localization file, the character's name will display as the raw key text rather than the intended content. Pay careful attention to which approach fits your use case.