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
}

实战 · 配合 · 坑

实战内容由 AI 生成,并已对照 vanilla 命令词表校验 —— 请当作起点而非权威依据。上方的定义节才是游戏自带文档原文。

实战用法

scope_exists 常用于专题研究(Special Project)或角色系统中,判断某个可选 scope 是否真实存在后再执行后续逻辑,避免对空 scope 进行无效判断。例如检查某个特殊项目是否已分配科学家,再决定是否显示特定 UI 提示或触发事件:

sp:sp_super_weapon = {
    character = {
        scope_exists = yes
        # 科学家存在时才检查其属性
        has_variable = my_scientist_flag
    }
}

配合关系

  • [has_variable](/wiki/trigger/has_variable):在确认 scope 存在之后,再检查该 scope 上是否挂载了特定变量,避免对不存在的 scope 读取变量时产生意外行为。
  • [any_of_scopes](/wiki/trigger/any_of_scopes):遍历一组潜在 scope 时,内层可用 scope_exists 过滤掉其中无效的成员,确保只对有效 scope 进行判断。
  • [if](/wiki/trigger/if):将 scope_exists 作为 if 的限定条件,使整段条件块只在 scope 有效时才被评估,逻辑更清晰。
  • [custom_trigger_tooltip](/wiki/trigger/custom_trigger_tooltip):包裹含 scope_exists 的判断,向玩家显示友好提示,说明某功能因关联 scope(如科学家)未存在而不可用。

常见坑

  1. 混淆 scope_existscountry_exists:新手常用 country_exists 来判断角色或项目关联的 scope 是否有效,但 country_exists 检查的是国家标签在游戏中是否存在,而非当前进入的 scope 本身是否成立,两者语义完全不同,在非国家 scope(如 charactersp: 等)中必须使用 scope_exists
  2. 在变量 scope 上多余使用:对 var: 类型的变量 scope 使用 scope_exists 永远返回 yes,因为变量 scope 始终合法,真正需要判断的应该是变量是否被赋值(用 [has_variable](/wiki/trigger/has_variable)),在这里加 scope_exists 不起任何过滤作用。

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.