Wiki

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

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

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
}

Synergy

  • [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.

Common Pitfalls

  1. Confusing local and global targets: Targets saved via 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.
  2. Writing the target name as a variable reference: The parameter to 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.