Wiki

trigger · any_collection_element

Definition

  • Supported scope:any
  • Supported target:THIS, ROOT, PREV, FROM, OWNER, CONTROLLER, OCCUPIED, CAPITAL

Description

Checks if the triggers are true for any of the elements in the collection.
If optional parameter `count` is set, then it checks if the number of elements that the trigger is true for is equal or larger than `count`.

### Example

any_collection_element = { collection = { input = game:scope operators = { controlled_states } } is_core_of = PREV } any_collection_element = { collection = { input = game:scope operators = { controlled_states } } is_core_of = PREV count = 3 }

实战 · 配合 · 坑

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

实战用法

any_collection_element 常用于遍历动态构建的 scope 集合并做条件判断,例如检查某国控制的所有州中是否有至少一个满足特定条件,适合在复杂的科研、战争或傀儡网络逻辑中替代冗长的多重 or 嵌套。

# 检查当前国家控制的州中,是否有至少 2 个核心属于 PREV
trigger = {
    any_collection_element = {
        collection = {
            input = game:scope
            operators = { controlled_states }
        }
        is_core_of = PREV
        count = 2
    }
}

配合关系

  • all_collection_elements:与 any_collection_element 互补,前者要求集合内所有元素都满足条件,两者常用于同一 collection 定义下的全量与部分量对比。
  • collection_size:在使用 any_collection_element 前先用 collection_size 确认集合不为空,避免空集合导致逻辑误判。
  • count_triggers:当需要统计满足多个不同条件的触发数量时,与 any_collection_element 配合使用,共同完成复合计数逻辑。
  • every_collection_element:effect 侧的对应命令,当 any_collection_element 判断为真后,通常在 if 块内用 every_collection_element 对同一集合执行批量操作。

常见坑

  1. count 含义误解count 表示"至少满足 N 个元素"而非"恰好等于 N 个",若需精确数量匹配,需配合 not + 更高 count 值的嵌套来夹逼,直接写 count = 3 并不等同于"只有 3 个满足"。
  2. collection 的 input scope 指向错误input = game:scope 中的 scope 必须是当前上下文中合法的 scope 指针,初学者容易将其写成固定国家 tag 或省份 ID,导致集合构建失败、条件永远为假。

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_collection_element is commonly used to iterate over a dynamically built scope collection and evaluate conditions against its elements — for example, checking whether at least one state controlled by a country meets a specific requirement. It is well-suited for complex research, war, or puppet-network logic as a cleaner alternative to deeply nested or chains.

# Check whether at least 2 states controlled by the current country have cores belonging to PREV
trigger = {
    any_collection_element = {
        collection = {
            input = game:scope
            operators = { controlled_states }
        }
        is_core_of = PREV
        count = 2
    }
}

Synergy

  • all_collection_elements: The counterpart to any_collection_element — where any_collection_element requires at least one matching element, all_collection_elements requires every element to match. The two are often used together against the same collection definition to compare partial versus full satisfaction.
  • collection_size: Use collection_size before any_collection_element to confirm the collection is non-empty, preventing empty collections from producing misleading logic results.
  • count_triggers: When you need to tally how many distinct conditions are satisfied, combine count_triggers with any_collection_element to build composite counting logic.
  • every_collection_element: The effect-side counterpart. Once any_collection_element evaluates to true, it is common practice to use every_collection_element inside an if block to perform batch operations on the same collection.

Common Pitfalls

  1. Misunderstanding count: count means "at least N elements satisfy the condition," not "exactly N elements." If you need an exact match, you must bracket it with a not block using a higher count value — simply writing count = 3 does not mean "only 3 elements match."
  2. Wrong input scope in the collection: The scope referenced in input = game:scope must be a valid scope pointer in the current context. Beginners often mistakenly write a hardcoded country tag or province ID there, causing the collection to fail to build and the condition to always evaluate as false.