Wiki

trigger · scope_exists

Definition

  • Supported scope:any
  • Supported target:none

Description

Check if the current scope exist.
This differ from for example exists that checks if the country of the scope exists.
This checks if the scope for the country exists and the other if the country itself exists in the game.
Note that variable scopes are always valid scopes.
Example:
DEN = { exists = yes } # Should always be true since DEN is always a valid scope
sp:sp_land_flamethrower_tank = {
	character = {
		scope_exists = yes
	}
} # True if the project has an assigned scientist.
var:my_var = {
	scope_exists = yes # Always true since variables are always valid scopes
}

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

scope_exists is commonly used in Special Projects or character systems to check whether an optional scope actually exists before executing subsequent logic, preventing invalid checks on null scopes. For example, checking whether a scientist has been assigned to a special project before deciding whether to display a specific UI prompt or trigger an event:

sp:sp_super_weapon = {
    character = {
        scope_exists = yes
        # Only check scientist attributes if the scientist exists
        has_variable = my_scientist_flag
    }
}

Synergy

  • [has_variable](/wiki/trigger/has_variable): After confirming a scope exists, check whether a specific variable is attached to that scope, preventing unexpected behavior when reading variables from non-existent scopes.
  • [any_of_scopes](/wiki/trigger/any_of_scopes): When iterating over a group of potential scopes, use scope_exists in the inner layer to filter out invalid members and ensure only valid scopes are evaluated.
  • [if](/wiki/trigger/if): Use scope_exists as a limiting condition for if, so the entire conditional block is only evaluated when the scope is valid, making the logic clearer.
  • [custom_trigger_tooltip](/wiki/trigger/custom_trigger_tooltip): Wrap checks containing scope_exists to display a user-friendly tooltip explaining why a feature is unavailable because its associated scope (such as a scientist) does not exist.

Common Pitfalls

  1. Confusing scope_exists with country_exists: Beginners often use country_exists to check whether the scope associated with a character or project is valid, but country_exists checks whether a country tag exists in the game, not whether the current scope itself is established. These have completely different semantics—in non-country scopes (such as character, sp:, etc.), you must use scope_exists.
  2. Redundant use on variable scopes: Using scope_exists on var: type variable scopes always returns yes, because variable scopes are always valid. What you actually need to check is whether the variable has been assigned (use [has_variable](/wiki/trigger/has_variable)). Adding scope_exists here has no filtering effect.