trigger · has_event_target
Definition
- Supported scope:
any - Supported target:
any
Description
checks if current scope or global scope has the specified event target saved
has_event_targetanyanychecks if current scope or global scope has the specified event target saved
实战内容由 AI 生成,并已对照 vanilla 命令词表校验 —— 请当作起点而非权威依据。上方的定义节才是游戏自带文档原文。
has_event_target 常用于事件链或决策脚本中,在触发后续逻辑前先确认某个通过 save_event_target_as 保存的目标确实存在,避免脚本在目标为空时崩溃或产生意外行为。例如在一个外交事件链中,保存了谈判对象国后,后续选项需要验证该目标仍有效:
# 在事件选项的 trigger/available 中校验之前保存的目标
available = {
has_event_target = negotiation_partner
}
[save_event_target_as](/wiki/effect/save_event_target_as) — 负责将某个 scope 存储为具名目标,has_event_target 通常在其之后用于验证该目标已成功存入。[save_global_event_target_as](/wiki/effect/save_global_event_target_as) — 保存全局目标时同样需要 has_event_target 在后续逻辑中做存在性检查,两者形成"写入–校验"的标准配对。[clear_global_event_target](/wiki/effect/clear_global_event_target) — 清除全局目标前可先用 has_event_target 确认目标存在,防止对空目标执行清除操作产生脚本警告。[scope_exists](/wiki/trigger/scope_exists) — 两者常并列出现:has_event_target 确认目标名称已注册,scope_exists 进一步确认该 scope 对应的对象(如国家)在游戏中依然存活。save_event_target_as 保存的本地目标仅在当前事件/效果块的生命周期内有效,跨事件后再用 has_event_target 检查会返回假;若需跨事件持久存储,必须改用 save_global_event_target_as,否则逻辑永远不会通过。has_event_target 的参数是硬编码的字符串标识符,不能传入变量或动态名称,新手有时误写成 has_event_target = var:some_variable,这会导致检测永远失败且不报明显错误。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.
has_event_target is commonly used in event chains or decision scripts to verify that a target previously saved via save_event_target_as actually exists before proceeding with subsequent logic, preventing script crashes or unexpected behavior when the target is null. For example, in a diplomatic event chain where a negotiation partner has been saved, subsequent options need to validate that the target remains valid:
# Verify the previously saved target in the event option's trigger/available block
available = {
has_event_target = negotiation_partner
}
[save_event_target_as](/wiki/effect/save_event_target_as) — Responsible for storing a scope as a named target; has_event_target is typically used afterward to verify that the target has been successfully registered.[save_global_event_target_as](/wiki/effect/save_global_event_target_as) — When saving global targets, has_event_target is equally needed in subsequent logic to perform existence checks, with the two forming a standard "write–verify" pairing.[clear_global_event_target](/wiki/effect/clear_global_event_target) — Before clearing a global target, you can use has_event_target to confirm the target exists first, preventing script warnings from attempting to clear a null target.[scope_exists](/wiki/trigger/scope_exists) — The two often appear in tandem: has_event_target confirms the target name has been registered, while scope_exists further confirms that the scope's corresponding object (such as a country) is still alive in the game.save_event_target_as are only valid within the current event/effect block's lifetime; checking with has_event_target across events will return false. If persistent storage across events is needed, you must use save_global_event_target_as instead, otherwise the logic will never pass.has_event_target is a hardcoded string identifier and cannot accept variables or dynamic names. Beginners sometimes mistakenly write has_event_target = var:some_variable, which causes the check to always fail silently without obvious errors.