Wiki

trigger · all_of_scopes

Definition

  • Supported scope:any
  • Supported target:any

Description

Runs a loop on an array and check a trigger for each scope in it, if any false returns false. otherwise returns true
Example: all_of_scopes = {
	array = array_name
	tooltip = loc #if defined the trigger will output tooltip using this title. loc_NOT will be used if trigger is inside a NOT
 #trigger 1
 #trigger 2 ...
}

实战 · 配合 · 坑

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

实战用法

all_of_scopes 常用于需要对一个动态数组中的所有元素逐一验证某条件的场景,例如检查存储在数组里的一批国家是否全部满足某个变量阈值,或验证玩家手动收集的省份列表是否全部符合建设条件。与 any_of_scopes 形成互补——前者要求全部为真,后者只需一个为真。

# 检查数组 target_countries 中的所有国家是否都存在
trigger = {
    all_of_scopes = {
        array = target_countries
        country_exists = THIS
    }
}

配合关系

  • add_to_array / add_to_temp_array:在执行 all_of_scopes 之前,先将需要检查的 scope 逐个压入数组,是最常见的前置操作。
  • any_of_scopes:与 all_of_scopes 形成"全部满足 vs 任意满足"的语义对,常在同一 and/or 块中组合使用以构造复杂条件。
  • is_in_array:用于在循环体内部进一步判断当前 scope 是否也出现在另一个数组中,实现数组交集检查。
  • check_variable:在循环体内对每个 scope 附带的数值变量进行门槛判断,是循环体中最高频的内层 trigger。

常见坑

  1. 忘记 array 字段或数组未初始化:若 array 指向一个从未被 add_to_array 写入过的变量名,数组为空时 all_of_scopes 会直接返回 true(空集上的全称命题成立),这与直觉相悖,可能导致条件意外通过。
  2. all_of_scopes 内部误用 effect 命令:该 trigger 只能包含条件判断(trigger 侧命令),若将 set_variableadd_to_array 等 effect 写入循环体,脚本解析会报错或静默忽略,需改用 for_each_scope_loop 来遍历数组执行 effect。

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

all_of_scopes is commonly used when you need to validate a condition against every element in a dynamic array — for example, checking whether all countries stored in an array meet a certain variable threshold, or verifying that a player-assembled list of provinces all satisfy construction requirements. It forms a natural complement to any_of_scopes: the former requires every element to be true, while the latter only requires one.

# Check whether all countries in the array target_countries exist
trigger = {
    all_of_scopes = {
        array = target_countries
        country_exists = THIS
    }
}

Synergy

  • add_to_array / add_to_temp_array: The most common prerequisite pattern — push each scope you want to check into the array before evaluating all_of_scopes.
  • any_of_scopes: The semantic counterpart to all_of_scopes, expressing "any one is true" versus "all are true." The two are frequently combined inside the same and/or block to build complex conditions.
  • is_in_array: Used inside the loop body to further check whether the current scope also appears in another array, effectively implementing an array-intersection check.
  • check_variable: The most frequently used inner trigger inside loop bodies — evaluates a numeric variable associated with each scope against a threshold.

Common Pitfalls

  1. Missing the array field or using an uninitialized array: If array points to a variable name that has never been written to by add_to_array, the array will be empty and all_of_scopes will return true immediately (a universal statement over an empty set is vacuously true). This is counterintuitive and can cause conditions to pass unexpectedly.
  2. Accidentally using effect commands inside all_of_scopes: This is a trigger-side construct and may only contain condition checks (trigger-side commands). Writing effects such as set_variable or add_to_array inside the loop body will cause a script parse error or be silently ignored. Use for_each_scope_loop instead when you need to iterate over an array and execute effects.