Wiki

trigger · any_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 true returns true. otherwise returns false
Example: any_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 命令词表校验 —— 请当作起点而非权威依据。上方的定义节才是游戏自带文档原文。

实战用法

any_of_scopes 常用于遍历一个自定义数组,检查其中是否有任意一个元素满足特定条件,例如判断某个存储了国家标签的数组中是否有至少一个国家持有全局旗帜,或某变量数组中是否存在达到阈值的值。典型场景包括动态联盟检查、多目标事件触发条件等。

# 检查数组 my_countries_array 中是否有任意国家拥有某全局旗帜
trigger = {
    any_of_scopes = {
        array = my_countries_array
        has_global_flag = special_event_flag
    }
}

配合关系

  • add_to_array / add_to_temp_array:在 effect 侧将国家或状态依次写入数组,随后在 trigger 侧用 any_of_scopes 遍历检查,是最典型的数组构建→检查工作流。
  • all_of_scopes:与 any_of_scopes 语义相对,用于要求数组中所有元素都满足条件,二者常并列出现以实现"至少一个/全部"的双重判断。
  • count_triggers:当需要知道数组中满足条件的元素数量而非仅判断有无时,用 count_triggers 替代或补充,二者常一起出现于复杂条件块中。
  • is_in_array:用于检查某个特定值是否已存在于数组内,与 any_of_scopes 配合可在遍历前做快速存在性预筛。

常见坑

  1. 忘记指定 array 字段any_of_scopes 必须通过 array = 数组名 明确指定要遍历的数组,直接在块内写 trigger 而不写 array 会导致脚本静默失效或报错,新手容易误以为可以像 any_country 那样省略来源声明。
  2. 在 trigger 侧的 scope 与数组存储的 scope 类型不匹配:数组中存储的是国家 scope 时,内部写的 trigger 必须对国家 scope 有效;若数组存的是数值变量而非 scope 对象,直接用 scope 类 trigger 检查会无效,应改用 check_variable 等数值类 trigger。

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_scopes is commonly used to iterate over a custom array and check whether at least one element satisfies a given condition — for example, determining whether any country stored in a country-tag array holds a global flag, or whether any value in a variable array has reached a threshold. Typical use cases include dynamic alliance checks and multi-target event trigger conditions.

# Check whether any country in my_countries_array holds a specific global flag
trigger = {
    any_of_scopes = {
        array = my_countries_array
        has_global_flag = special_event_flag
    }
}

Synergy

  • add_to_array / add_to_temp_array: On the effect side, countries or states are written into an array one by one; on the trigger side, any_of_scopes iterates over that array to check conditions. This is the most typical array-build → array-check workflow.
  • all_of_scopes: The semantic counterpart of any_of_scopes — it requires all elements in the array to satisfy the condition. The two are often used side by side to implement "at least one / all" dual checks.
  • count_triggers: When you need to know the number of elements that satisfy a condition rather than simply whether any exist, use count_triggers as a replacement or supplement. The two frequently appear together inside complex condition blocks.
  • is_in_array: Used to check whether a specific value already exists in an array. Pairing it with any_of_scopes allows for a quick existence pre-filter before iterating.

Common Pitfalls

  1. Forgetting to specify the array field: any_of_scopes requires an explicit array = <array_name> declaration. Writing triggers inside the block without specifying array will cause the script to silently fail or throw an error. Beginners often assume it can be used like any_country, where the source scope declaration can be omitted.
  2. Mismatch between the scope type in the trigger and the scope type stored in the array: When the array stores country scopes, the triggers written inside must be valid for country scopes. If the array stores numeric variables rather than scope objects, using scope-based triggers to check them will have no effect — use numeric triggers such as check_variable instead.