Wiki

trigger · any_of

Definition

  • Supported scope:any
  • Supported target:any

Description

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

实战 · 配合 · 坑

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

实战用法

any_of 常用于遍历自定义数组,判断其中是否存在至少一个满足特定条件的元素,例如检查某个存储了国家标签或数值的数组中是否有任何值符合阈值,从而控制事件选项的可用性或 focus 的 available 块。

# 检查数组 target_states 中是否有任何一个 index 对应的变量值大于 5
available = {
    any_of = {
        array = target_states
        value = current_val
        index = i
        check_variable = {
            var = current_val
            value = 5
            compare = greater_than
        }
    }
}

配合关系

  • add_to_array / add_to_temp_array:在 effect 侧先向数组填充数据,再用 any_of 在 trigger 侧遍历检查,是最典型的"写入-读取"配对模式。
  • all_of:两者语义互补,all_of 要求数组中每个元素均满足条件,any_of 只要有一个满足即可,常结合使用来表达复杂逻辑。
  • check_variableany_of 循环体内最常见的判断命令,用于对当前迭代值(value)或关联变量进行数值比较。
  • count_triggers:当需要知道"满足条件的元素有多少个"而非"是否存在"时,可与 any_of 搭配或替换使用,做更精确的数量判断。

常见坑

  1. 漏写 array 字段或数组名拼写有误any_of 必须指定 array = <数组名>,若数组尚未被 add_to_arrayadd_to_temp_array 初始化就调用,循环体不会执行,any_of 会直接返回 false,导致条件永远不成立却难以察觉。
  2. value/index 占位变量名与已有全局变量重名valueindex 是当前迭代的临时变量名,若与脚本其他地方的 set_variable 同名变量冲突,会在循环期间意外覆盖或读取到错误的值,应使用具有唯一性的自定义名称(如 value = my_loop_val)以避免污染。

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

any_of is commonly used to iterate over a custom array and check whether at least one element satisfies a specific condition — for example, checking whether any value stored in an array of country tags or numbers meets a threshold, in order to control the availability of event options or a focus's available block.

# Check whether any index in the array target_states has a corresponding variable value greater than 5
available = {
    any_of = {
        array = target_states
        value = current_val
        index = i
        check_variable = {
            var = current_val
            value = 5
            compare = greater_than
        }
    }
}

Synergy

  • add_to_array / add_to_temp_array: The most typical "write-then-read" pairing pattern — populate the array on the effect side first, then use any_of on the trigger side to iterate and check.
  • all_of: Semantically complementary to any_of. While all_of requires every element in the array to satisfy the condition, any_of only requires one. The two are often combined to express complex logic.
  • check_variable: The most common check used inside an any_of loop body, used to perform numerical comparisons against the current iteration value (value) or a related variable.
  • count_triggers: When you need to know how many elements satisfy a condition rather than simply whether any do, this can be used alongside or as a replacement for any_of for more precise quantity-based checks.

Common Pitfalls

  1. Missing the array field or a typo in the array name: any_of requires array = <array_name> to be specified. If the array has not yet been initialized via add_to_array or add_to_temp_array when the trigger is evaluated, the loop body will not execute and any_of will immediately return false — causing the condition to silently never be met.
  2. Naming the value/index placeholder variables the same as existing global variables: value and index are temporary variable names scoped to the current iteration. If they share a name with a variable set elsewhere via set_variable, they may unexpectedly overwrite or read incorrect values during the loop. Use unique, descriptive names (e.g., value = my_loop_val) to avoid polluting the variable namespace.