Wiki

trigger · all_collection_elements

Definition

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

Description

Checks if the triggers are true for all of the elements in the collection.

### Example

all_collection_elements = { collection = { input = game:scope operators = { controlled_states } } is_core_of = PREV }

实战 · 配合 · 坑

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

实战用法

all_collection_elements 常用于需要对动态数组或集合中每一个元素都满足某条件时的检验,例如判断某国所有受控州是否全部为自己的核心州,或验证一个自定义数组里的所有国家是否都达成了某项条件。相比多个 any_of 嵌套,它能简洁地处理长度不定的集合。

# 检查某国控制的所有州是否全部是本国核心
all_collection_elements = {
    collection = {
        input = game:scope
        operators = { controlled_states }
    }
    is_core_of = PREV
}

# 检查自定义数组 target_states 中的所有元素是否都满足条件
all_collection_elements = {
    collection = target_states
    is_owned_by = ROOT
}

配合关系

  • any_collection_elementall_collection_elements 验证"全部满足",与之互补的 any_collection_element 验证"至少一个满足",两者常配合做集合的全量与局部校验。
  • collection_size:使用前先用 collection_size 确认集合非空,避免空集合时 all_collection_elements 因无元素可检而静默返回真导致逻辑误判。
  • add_to_temp_array / is_in_array:先用 add_to_temp_array 构造临时集合,再传入 all_collection_elements 做统一验证,是动态构造检验集合的标准流程。
  • count_triggers:当需要"满足条件的元素数量"而非"是否全部满足"时,改用 count_triggers 更合适,两者经常在同一 trigger 块中对比使用。

常见坑

  1. 空集合静默返回真:当传入的集合或数组长度为 0 时,all_collection_elements 会直接返回 true(逻辑上"对空集全称命题成立"),导致条件块在不应通过时意外通过。务必在外层用 collection_sizeand 组合先过滤空集合的情况。
  2. PREV 指向理解错误all_collection_elements 的内部 scope 切换到集合元素本身,此时 PREV 指向进入该 trigger 之前的 scope(通常是调用国),而非集合的来源对象。新手常误以为 PREV 指向集合定义处的对象,导致 is_core_of = PREV 等写法引用了错误的目标。

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_collection_elements is commonly used when you need to verify that every element in a dynamic array or collection satisfies a given condition — for example, checking whether all states controlled by a country are also its core states, or confirming that every country in a custom array has met a particular condition. Compared to nesting multiple any_of checks, it handles variable-length collections in a much cleaner way.

# Check whether all states controlled by a country are its own cores
all_collection_elements = {
    collection = {
        input = game:scope
        operators = { controlled_states }
    }
    is_core_of = PREV
}

# Check whether every element in the custom array target_states satisfies the condition
all_collection_elements = {
    collection = target_states
    is_owned_by = ROOT
}

Synergy

  • any_collection_element: all_collection_elements tests "all elements match," while its complement any_collection_element tests "at least one matches." The two are often used together for full and partial validation of a collection.
  • collection_size: Use collection_size beforehand to confirm the collection is non-empty. If the collection is empty, all_collection_elements silently returns true — which can cause logic errors if left unchecked.
  • add_to_temp_array / is_in_array: The standard pattern for dynamic validation is to build a temporary collection with add_to_temp_array and then pass it into all_collection_elements for unified evaluation.
  • count_triggers: When you need to know how many elements satisfy a condition rather than whether all of them do, count_triggers is the better fit. The two are often compared side by side within the same trigger block.

Common Pitfalls

  1. Empty collections silently return true: When the collection or array passed in has a length of 0, all_collection_elements immediately returns true (logically, a universal statement over an empty set is vacuously true). This can cause a condition block to pass unexpectedly when it shouldn't. Always guard against empty collections in the outer scope using collection_size or an and combination.
  2. Misunderstanding what PREV points to: Inside all_collection_elements, the scope shifts to each collection element in turn. At that point, PREV refers to the scope that was active before entering the trigger — typically the calling country — not the object from which the collection was derived. Beginners often assume PREV points to the object where the collection was defined, leading to incorrect references in expressions like is_core_of = PREV.