Wiki

trigger · collection_contains

Definition

  • Supported scope:any
  • Supported target:any

Description

Checks if the provided collection contains all the provided elements. Possible types to check for are:
- Countries

### Example

collection_contains = { collection = game:all_countries countries = { ENG GER } } collection_contains = { collection = game:all_countries country = FRA }

实战 · 配合 · 坑

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

实战用法

collection_contains 常用于检测玩家自定义集合(如通过脚本动态维护的国家列表)是否已包含特定成员,典型场景包括:联盟系统中验证某些核心国家是否全部加入、成就条件校验特定国家是否同时存在于某个阵营集合。以下示例检查自定义收集的国家集合是否同时包含英国和法国:

# 在 trigger 块中判断"轴心国监视名单"是否涵盖 ENG 和 FRA
collection_contains = {
    collection = global.axis_watchlist
    countries = { ENG FRA }
}

配合关系

  • [any_collection_element](/wiki/trigger/any_collection_element):当只需判断集合中是否存在满足某条件的元素(而非固定国家标签)时,与 collection_contains 互补搭配使用。
  • [collection_size](/wiki/trigger/collection_size):先用 collection_size 验证集合非空或达到预期规模,再用 collection_contains 确认关键成员存在,避免对空集合误判。
  • [add_to_temp_array](/wiki/effect/add_to_temp_array):在 effect 块里动态向临时数组填入国家,随后在 trigger 中用 collection_contains 验证填充结果是否符合预期,实现"构建后校验"流程。
  • [all_collection_elements](/wiki/trigger/all_collection_elements):若需确保集合中每一个元素都满足某条件,而非判断集合是否含有某固定元素,可与 collection_contains 分工使用。

常见坑

  1. 混淆单数与复数字段country(单个标签)与 countries(多个标签的块)是两个不同字段,新手常把多个标签写进 country = { ENG FRA } 导致语法报错或静默失效,应改用 countries = { ENG FRA }
  2. 对普通数组直接使用collection_contains 仅支持特定类型的集合(如国家),若将其用于普通变量数组,应改用 [is_in_array](/wiki/trigger/is_in_array) 来检测元素是否存在,否则条件永远不会如期触发。

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

collection_contains is commonly used to verify whether player-defined collections (such as dynamically maintained country lists via script) contain specific members. Typical use cases include verifying that certain core nations have all joined an alliance system, and validating achievement conditions to check whether specific countries simultaneously exist within a faction collection. The following example checks whether a custom-collected country collection contains both England and France:

# Check if the "axis watchlist" collection encompasses ENG and FRA in a trigger block
collection_contains = {
    collection = global.axis_watchlist
    countries = { ENG FRA }
}

Synergy

  • [any_collection_element](/wiki/trigger/any_collection_element): Use this in complement with collection_contains when you only need to check whether an element satisfying a condition exists in the collection (rather than fixed country tags).
  • [collection_size](/wiki/trigger/collection_size): First use collection_size to verify that the collection is non-empty or reaches the expected scale, then use collection_contains to confirm that key members exist, avoiding false positives with empty collections.
  • [add_to_temp_array](/wiki/effect/add_to_temp_array): Dynamically populate countries into a temporary array in an effect block, then verify in a trigger using collection_contains that the populated results meet expectations, implementing a "build-then-validate" workflow.
  • [all_collection_elements](/wiki/trigger/all_collection_elements): If you need to ensure that every element in the collection satisfies a condition, rather than checking whether the collection contains a fixed element, you can use this alongside collection_contains with clear separation of duties.

Common Pitfalls

  1. Confusing singular and plural fields: country (single tag) and countries (block of multiple tags) are two different fields. Beginners often mistakenly write multiple tags into country = { ENG FRA } causing syntax errors or silent failures; use countries = { ENG FRA } instead.
  2. Using directly on ordinary arrays: collection_contains only supports specific collection types (such as countries). If you attempt to use it on ordinary variable arrays, switch to [is_in_array](/wiki/trigger/is_in_array) to check whether an element exists; otherwise the condition will never trigger as expected.