Wiki

effect · save_global_event_target_as

Definition

  • Supported scope:any
  • Supported target:none

Description

save a global event target

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

save_global_event_target_as is commonly used in scenarios requiring cross-event, cross-country scope passing of specific object references. For example, in global story chains, you can record the "country that triggered a war" or "current negotiation target" so that any subsequent event can directly reference that object via event_target:xxx without repeated lookups. Typical applications include multi-country coordinated diplomatic event chains, global faction leader tracking, and dynamic country marking across scopes.

# In the immediate block of an event, save the current country as a global target
immediate = {
    save_global_event_target_as = negotiation_initiator
}

# In any subsequent event or effect, you can directly reference:
# event_target:negotiation_initiator = { ... }

Synergy

  • [clear_global_event_target](/wiki/effect/clear_global_event_target): After saving a global target, promptly clear it when the story chain concludes or the target becomes invalid, preventing stale references from polluting subsequent logic.
  • [save_event_target_as](/wiki/effect/save_event_target_as): The local version of target saving, commonly paired with the global version—use the local target for temporary calculations within the current event, then persist the result using the global version.
  • [has_event_target](/wiki/trigger/has_event_target): Check whether the target exists before using event_target:xxx to prevent script errors caused by the global target not being correctly saved.
  • [if](/wiki/effect/if): Combine with conditional checks to execute the save operation only when specific conditions are met, avoiding accidental overwriting of existing global target references.

Common Pitfalls

  1. Global targets get overwritten by subsequent calls: A global target with the same name will be silently overwritten whenever save_global_event_target_as is called from any scope. When multiple event chains share the same target name, a "late-comer overwrites early-comer" race condition easily occurs. Always use unique naming for different execution paths.
  2. Dangling targets from forgotten cleanup: Global targets persist throughout the entire game session. If the saved country or state becomes invalid (e.g., eliminated), continuing to reference that target will not trigger an error but will cause logic to fail silently. Explicitly call clear_global_event_target to clean up when the event chain ends.