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
- 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.
- 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.