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