Wiki

effect · clear_global_event_targets

Definition

  • Supported scope:any
  • Supported target:THIS, ROOT, PREV, FROM, OWNER, CONTROLLER, OCCUPIED, CAPITAL

Description

clear all global event targets

实战 · 配合 · 坑

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

实战用法

clear_global_event_targets 适合在 mod 的"重置/清档"场景中使用,例如大型事件链结束后统一清除所有通过 save_global_event_target_as 保存的全局目标,防止残留引用污染后续逻辑。也常用于游戏开局初始化脚本,确保没有任何遗留的全局事件目标干扰第一次触发。

# 在某个"重置世界局势"事件的 immediate 块中
news_event = {
    id = my_mod.999
    immediate = {
        clear_global_event_targets = yes
    }
}

配合关系

  • [save_global_event_target_as](/wiki/effect/save_global_event_target_as):与之相对的"存储"指令,通常先批量保存全局目标,在事件链尾部再用本指令一次性清除,形成完整的生命周期管理。
  • [clear_global_event_target](/wiki/effect/clear_global_event_target):用于精准删除单个全局目标;当只需要清理特定目标而非全部时,两者形成互补选择。
  • [clr_global_flag](/wiki/effect/clr_global_flag):常与本指令搭配在同一个"重置"块中,同步清除全局标记,保证状态完全归零。
  • [has_event_target](/wiki/trigger/has_event_target):在清除前可用此触发器检查某全局目标是否存在,辅助调试或条件分支保护。

常见坑

  1. 误用范围过宽:本指令会清除所有全局事件目标,包括其他不相关系统保存的目标。若 mod 中多个模块共用全局事件目标命名空间,在错误时机调用会连带删除不该删的目标,导致其他事件链报错或行为异常。应在确认所有模块均不再依赖全局目标时才调用。
  2. clear_global_event_target 混淆:新手常将两者写反——单数形式 clear_global_event_target 需要指定目标名称作为参数,而本指令无需参数直接写 = yes;若将本指令当作单数版本使用并传入名称,脚本将无法正常解析。

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_targets is best suited for "reset/wipe" scenarios in mods, such as clearing all global targets saved via save_global_event_target_as at the end of a large event chain to prevent stale references from polluting downstream logic. It's also commonly used in game initialization scripts to ensure no orphaned global event targets interfere with the first trigger.

# In the immediate block of a "reset world situation" event
news_event = {
    id = my_mod.999
    immediate = {
        clear_global_event_targets = yes
    }
}

Synergy

  • [save_global_event_target_as](/wiki/effect/save_global_event_target_as): The complementary "storage" command; typically you batch-save global targets first, then use this command at the end of an event chain for wholesale cleanup, forming a complete lifecycle management pattern.
  • [clear_global_event_target](/wiki/effect/clear_global_event_target): Used to delete a single global target with precision; when only specific targets need cleanup rather than all, these two form a complementary choice.
  • [clr_global_flag](/wiki/effect/clr_global_flag): Often paired with this command in the same "reset" block to synchronously clear global flags and ensure state is completely reset.
  • [has_event_target](/wiki/trigger/has_event_target): Before clearing, use this trigger to check whether a specific global target exists, aiding debugging or conditional branch protection.

Common Pitfalls

  1. Overly broad scope misuse: This command clears all global event targets, including those saved by unrelated systems elsewhere. If multiple modules in your mod share the global event target namespace, calling this at the wrong time will inadvertently delete targets that shouldn't be deleted, causing other event chains to error or behave unexpectedly. Only call this after confirming all modules no longer depend on global targets.
  2. Confusion with clear_global_event_target: Beginners often get these backwards—the singular form clear_global_event_target requires a target name as a parameter, while this command takes no parameters and is simply written as = yes; if you try to use this command as a singular version and pass a name, the script will fail to parse correctly.