Wiki

effect · save_event_target_as

Definition

  • Supported scope:any
  • Supported target:none

Description

save an 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_event_target_as is commonly used in event chains or decision execution to temporarily store a current scope (such as a country or state) as a named target, allowing subsequent scripts to reference it cross-scope via event_target:xxx. Typical scenarios include: saving the "initiating country" when an event is triggered in a country, then applying effects to it in another country's event option, or recording a critical iteration object within a complex for_each_scope_loop for later logic reuse.

# In the immediate block of a country event, save itself as an event target
immediate = {
    save_event_target_as = initiating_country
}

# Can still be referenced in the option after switching scope
option = {
    name = MY_EVENT_OPTION_A
    every_country = {
        limit = { is_ally_with = event_target:initiating_country }
        add_political_power = 50
    }
}

Synergy

  • [has_event_target](/wiki/trigger/has_event_target): Before using a saved target, check whether it exists using this trigger to prevent script errors when the target is invalidated.
  • [save_global_event_target_as](/wiki/effect/save_global_event_target_as): Forms a complementary relationship with this command — targets saved by this command are only valid within the current event chain (temporarily), while the global version persists across the entire game session. Choose based on lifecycle requirements.
  • [clear_global_event_target](/wiki/effect/clear_global_event_target): When using the global version, typically pair it with this command in a workflow that follows the principle of "use save_event_target_as for temporary storage, use the global version for persistence, then clear promptly" to keep memory clean.
  • [hidden_effect](/wiki/effect/hidden_effect): Commonly wrap save_event_target_as within a hidden effect block to avoid exposing meaningless logs or tooltip text to the player.

Common Pitfalls

  1. Confusing scopes and saving the wrong object: save_event_target_as saves the object of the current scope, and beginners often mistakenly store the wrong country or state when confused between ROOT and FROM. It is recommended to clearly annotate in comments what the current scope is before writing.
  2. Assuming targets persist permanently: Event targets saved by this command (non-global version) have a lifecycle limited to the current event processing only. Once the event ends, they become invalid. If subsequent independent events or on_actions still need to reference them, you must use save_global_event_target_as instead and manually clear it at the appropriate time.