Wiki

trigger · all_of

Definition

  • Supported scope:any
  • Supported target:any

Description

Runs a loop on an array and check a trigger for each value, if any false returns false. otherwise returns true
Example: all_of = {
	array = array_name
	value = value_name #optional (default 'v') current value in array will be stored in this temp variable
	index = index_name #optional (default 'i') current index in array will be stored in this temp variable
 #trigger 1
 #trigger 2 ...
}

实战 · 配合 · 坑

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

实战用法

all_of 常用于需要遍历一个数组、验证其中每一个元素都满足某个条件的场景,例如检查玩家存入数组的所有国家标签是否都存在,或验证一组省份变量是否全部满足数值门槛。与 any_of 互补,all_of 要求"全员通过"才返回真,适合做"不允许任何例外"的严格校验。

# 检查临时数组 target_countries 中存储的所有国家 tag 是否全部存在
all_of = {
    array = target_countries
    value = v
    country_exists = v
}

配合关系

  • add_to_temp_array 在 effect 侧先将目标值逐一压入临时数组,再用 all_of 在 trigger 侧统一校验,是最常见的"收集→验证"组合。
  • any_ofall_of 语义互补,同一数组可先用 any_of 做宽松预检、再用 all_of 做严格过滤,形成层次化的条件链。
  • clear_temp_array 在循环结束后及时清空临时数组,防止上一次迭代残留数据污染 all_of 的判断结果。
  • check_variable 作为 all_of 内部的核心子条件,对数组每个数值元素执行具体的大小比较,是最常填入循环体的 trigger 之一。

常见坑

  1. 默认变量名冲突value 默认存入临时变量 vindex 默认存入 i;若外层逻辑已经使用了名为 vi 的临时变量,内层循环会静默覆盖它们,导致外层数据损坏——应显式指定 value = my_val 等不冲突的名称。
  2. 空数组返回真:当传入的数组长度为 0 时,all_of 没有任何元素需要检验,会直接返回 true("空集上的全称命题"逻辑上成立);若业务逻辑要求数组非空才算通过,需在 all_of 外额外用 check_variable 验证数组的 collection_size 大于 0。

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 is typically used when you need to iterate over an array and verify that every element satisfies a given condition — for example, checking whether all country tags stored in an array actually exist, or confirming that a set of province variables all meet a numeric threshold. As the counterpart to any_of, all_of requires every member to pass before returning true, making it the right tool for strict "no exceptions allowed" validation.

# Check whether every country tag stored in the temporary array target_countries exists
all_of = {
    array = target_countries
    value = v
    country_exists = v
}

Synergy

  • add_to_temp_array — Push target values into a temporary array one by one on the effect side, then use all_of on the trigger side to validate them all at once. This "collect → verify" pattern is the most common use case.
  • any_of — Semantically complementary to all_of. On the same array, you can use any_of for a loose preliminary check and then all_of for strict filtering, building a layered condition chain.
  • clear_temp_array — Clear the temporary array promptly after a loop finishes to prevent leftover data from a previous iteration from contaminating all_of's evaluation.
  • check_variable — The go-to sub-condition inside all_of for performing concrete numeric comparisons on each element of the array; it is one of the most frequently used triggers inside loop bodies.

Common Pitfalls

  1. Default variable name collisions: value defaults to the temporary variable v, and index defaults to i. If outer logic already uses temporary variables named v or i, the inner loop will silently overwrite them, corrupting the outer data. Always explicitly specify non-conflicting names such as value = my_val.
  2. Empty arrays return true: When the supplied array has zero elements, all_of has nothing to evaluate and returns true immediately (a universal statement over an empty set is vacuously true in formal logic). If your logic requires the array to be non-empty in order to pass, add an extra check_variable outside all_of to confirm the array's collection_size is greater than 0.