Wiki

effect · clear_global_event_target

Definition

  • Supported scope:any
  • Supported target:none

Description

clear a global event target

实战 · 配合 · 坑

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

实战用法

clear_global_event_target 常用于需要在事件或决议链结束后清理临时性全局目标的场景,例如某个多步骤外交事件链完成后,释放之前通过 save_global_event_target_as 保存的目标国家或州,避免残留目标影响后续逻辑判断。典型场景包括清除战争调解国、外交谈判代理方等临时性全局引用。

# 事件链结束时,在 immediate 块中清理之前保存的全局目标
immediate = {
    clear_global_event_target = my_mediator_country
}

配合关系

  • [save_global_event_target_as](/wiki/effect/save_global_event_target_as):这是最直接的配合对象,通常先用此命令保存全局目标,事件链结束或条件失效后再用 clear_global_event_target 清除,形成完整的生命周期管理。
  • [has_event_target](/wiki/trigger/has_event_target):在清除前可用此触发器检测全局目标是否存在,避免对不存在的目标执行清除时产生不必要的脚本警告。
  • [clear_global_event_targets](/wiki/effect/clear_global_event_targets):若需要一次性清除所有全局目标,可改用此命令;两者形成"精确清除"与"批量清除"的互补关系。
  • [if](/wiki/effect/if):配合条件块使用,可在满足特定条件(如事件链已完成)时才执行清除,使逻辑更加严谨。

常见坑

  1. 忘记清除导致目标残留:全局事件目标在整个游戏存档中持久存在,如果事件链提前中断(如目标国被消灭、玩家投降)而未及时清除,该目标会一直占用内存并可能被其他不相关逻辑误引用,因此务必在所有退出路径(包括取消选项)中都加入清除逻辑。
  2. 目标名称拼写不一致clear_global_event_target 的参数必须与 save_global_event_target_as 中定义的名称完全一致(区分大小写),一旦名称不匹配将静默失败,且游戏通常不会在日志中给出明确报错,极难排查。

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

clear_global_event_target is commonly used in scenarios where temporary global event targets need to be cleaned up after an event or decision chain concludes. For example, after completing a multi-step diplomatic event chain, you can release target countries or states previously saved via save_global_event_target_as, preventing residual targets from interfering with subsequent logic checks. Typical use cases include clearing war mediator countries, diplomatic negotiation proxies, and other temporary global references.

# Clean up previously saved global targets in the immediate block when the event chain ends
immediate = {
    clear_global_event_target = my_mediator_country
}

Synergy

  • [save_global_event_target_as](/wiki/effect/save_global_event_target_as): This is the most direct companion command. Typically you first save a global target with this command, then use clear_global_event_target to remove it after the event chain ends or conditions become invalid, forming a complete lifecycle management pattern.
  • [has_event_target](/wiki/trigger/has_event_target): You can use this trigger before clearing to detect whether a global target exists, avoiding unnecessary script warnings when attempting to clear non-existent targets.
  • [clear_global_event_targets](/wiki/effect/clear_global_event_targets): If you need to clear all global targets at once, you can use this command instead. The two form a complementary relationship between "precise clearing" and "batch clearing."
  • [if](/wiki/effect/if): Used together with conditional blocks, you can execute the clear operation only when specific conditions are met (such as when the event chain has completed), making your logic more rigorous.

Common Pitfalls

  1. Forgetting to clear leaves targets in memory: Global event targets persist throughout the entire game save. If an event chain is interrupted prematurely (such as the target country being eliminated or the player surrendering) without timely cleanup, that target will continue consuming memory and may be mistakenly referenced by unrelated logic. Therefore, you must add clear logic to all exit paths, including cancel options.
  2. Target name spelling inconsistencies: The parameter passed to clear_global_event_target must exactly match the name defined in save_global_event_target_as (case-sensitive). If names don't match, the operation will silently fail, and the game typically won't provide clear error messages in logs, making it extremely difficult to debug.