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