Hands-On Usage
count_in_collection is commonly used to detect the number of faction members, units of a certain type, or the scale of deployed forces, thereby dynamically unlocking decisions, triggering events, or restricting national focuses. For example, you can use it to determine whether the faction that the player belongs to has reached a certain scale before allowing a "unified action" decision to appear:
available = {
count_in_collection = {
collection = {
input = game:scope
operators = { faction_members }
name = FACTION
}
size > 4
}
}
Synergy
[any_faction_member](/wiki/trigger/any_faction_member) / [all_faction_member](/wiki/trigger/all_faction_member) (not in the whitelist, but can reference those in the whitelist) → Use in conjunction with [has_completed_focus](/wiki/trigger/has_completed_focus): first use count_in_collection to confirm that the faction scale meets the threshold, then use this trigger to check whether members have completed a specific national focus. Together, they form a more precise condition gate.
[add_faction_goal](/wiki/effect/add_faction_goal): typically only append new goals to the faction after count_in_collection confirms that the faction member count meets the requirements, avoiding triggering invalid logic when the faction scale is insufficient.
[faction_influence_ratio](/wiki/trigger/faction_influence_ratio): when combined with count_in_collection, both the "scale" and "influence ratio" of the faction can be constrained simultaneously. This dual filtering ensures that only truly dominant major factions can trigger specific narrative events.
[activate_targeted_decision](/wiki/effect/activate_targeted_decision): once count_in_collection passes the judgment, use this effect to batch activate targeted decisions against faction members, implementing a linked mechanism that triggers when the scale threshold is met.
Common Pitfalls
unit, buildings, manpower are mutually exclusive (choose one): beginners often write multiple filter fields simultaneously (such as writing both unit = armor and manpower = yes), which causes script errors or undefined behavior. You must keep only one of them, or write none of the three (in which case the count is the number of elements in the collection itself).
operators in collection is written incorrectly, resulting in an empty set: operators determines how the set is expanded from the input scope. If you use operators that are not applicable to the current scope (for example, using faction_members under a non-faction country scope), the collection returns an empty set and size > 0 is always false. However, the script will not report an error, making it extremely difficult to debug.