effect · save_event_target_as
Definition
- Supported scope:
any - Supported target:
none
Description
save an event target
save_event_target_asanynonesave an event target
实战内容由 AI 生成,并已对照 vanilla 命令词表校验 —— 请当作起点而非权威依据。上方的定义节才是游戏自带文档原文。
save_event_target_as 常用于在事件链或决议执行中,将某个当前作用域(如一个国家或状态)暂存为命名目标,以便后续脚本通过 event_target:xxx 跨作用域引用它。典型场景包括:在一个国家触发事件时保存"发起国",然后在另一国的事件 option 中对其执行效果,或在复杂的 for_each_scope_loop 中记录某个关键迭代对象供后续逻辑复用。
# 在某国事件的 immediate 块中,将自身保存为事件目标
immediate = {
save_event_target_as = initiating_country
}
# 随后在 option 中切换作用域后仍可引用
option = {
name = MY_EVENT_OPTION_A
every_country = {
limit = { is_ally_with = event_target:initiating_country }
add_political_power = 50
}
}
[has_event_target](/wiki/trigger/has_event_target):在使用保存的目标之前,先用此触发器检查该目标是否存在,避免目标失效时脚本报错。[save_global_event_target_as](/wiki/effect/save_global_event_target_as):与本命令形成互补——本命令保存的目标仅在当前事件链(临时)生效,而全局版本跨越整个游戏会话持久存在,需根据生命周期需求选择。[clear_global_event_target](/wiki/effect/clear_global_event_target):当使用全局版本时,往往与本命令搭配规划"临时用 save_event_target_as,持久用 global 版本后及时清除"的工作流,保持内存整洁。[hidden_effect](/wiki/effect/hidden_effect):常将 save_event_target_as 包裹在隐藏效果块中,避免向玩家暴露无意义的日志或 tooltip 文本。save_event_target_as 保存的是当前所在 scope 的对象,新手常在 ROOT 与 FROM 混淆的情况下误存了错误的国家或状态,建议在写之前明确用注释标注当前 scope 是什么。save_global_event_target_as 并在合适时机手动清除。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.
save_event_target_as is commonly used in event chains or decision execution to temporarily store a current scope (such as a country or state) as a named target, allowing subsequent scripts to reference it cross-scope via event_target:xxx. Typical scenarios include: saving the "initiating country" when an event is triggered in a country, then applying effects to it in another country's event option, or recording a critical iteration object within a complex for_each_scope_loop for later logic reuse.
# In the immediate block of a country event, save itself as an event target
immediate = {
save_event_target_as = initiating_country
}
# Can still be referenced in the option after switching scope
option = {
name = MY_EVENT_OPTION_A
every_country = {
limit = { is_ally_with = event_target:initiating_country }
add_political_power = 50
}
}
[has_event_target](/wiki/trigger/has_event_target): Before using a saved target, check whether it exists using this trigger to prevent script errors when the target is invalidated.[save_global_event_target_as](/wiki/effect/save_global_event_target_as): Forms a complementary relationship with this command — targets saved by this command are only valid within the current event chain (temporarily), while the global version persists across the entire game session. Choose based on lifecycle requirements.[clear_global_event_target](/wiki/effect/clear_global_event_target): When using the global version, typically pair it with this command in a workflow that follows the principle of "use save_event_target_as for temporary storage, use the global version for persistence, then clear promptly" to keep memory clean.[hidden_effect](/wiki/effect/hidden_effect): Commonly wrap save_event_target_as within a hidden effect block to avoid exposing meaningless logs or tooltip text to the player.save_event_target_as saves the object of the current scope, and beginners often mistakenly store the wrong country or state when confused between ROOT and FROM. It is recommended to clearly annotate in comments what the current scope is before writing.save_global_event_target_as instead and manually clear it at the appropriate time.