Hands-On Usage
get_sorted_scored_countries_temp is commonly used in AI diplomatic decisions or events when you need to sort all countries by a custom score (such as threat level, opinion, or military strength) and access a specific ranked country. For example, in a decision to "find the best ally target," use this trigger to sort candidate countries by a custom scoring function, then iterate through the temporary array:
available = {
get_sorted_scored_countries_temp = {
scorer = best_ally_scorer
array = candidate_countries
scores = candidate_scores
}
# After sorting, the array can be used in the same trigger block or subsequent effects
count_in_collection = {
array = candidate_countries
count > 0
}
}
Synergy
[get_highest_scored_country_temp](/wiki/trigger/get_highest_scored_country_temp): After sorting the complete list, if you only need the single highest-scoring country, use this trigger to directly fetch the top entry. The two triggers complement each other logically.
[count_in_collection](/wiki/trigger/count_in_collection): Validates that the array actually contains valid countries after sorting, preventing logic errors from operating on empty arrays.
[get_sorted_scored_countries](/wiki/effect/get_sorted_scored_countries): The effect version corresponds semantically to this trigger. Use it when you need to execute the same sorting operation within an effect block. Both share identical parameter structures and can be cross-referenced.
[get_highest_scored_country_temp](/wiki/effect/get_highest_scored_country_temp): Retrieves the highest-scoring country after sorting and stores it in a temporary variable on the effect side. Commonly paired with this trigger in the available/effect workflow.
Common Pitfalls
- Assuming arrays persist across scopes: The
_temp suffix means the array only lives within the current scope or event execution cycle. You cannot reference it across scopes or between events after this trigger completes. Beginners often copy temporary array names into effect blocks expecting persistent storage, only to find the data is already invalid.
- Forgetting that scorer must be registered in
country_scorer: The id specified in scorer = xxx must have a corresponding definition in the common/country_scorer/ folder. Entering a non-existent id won't cause an error, but the array will be empty, making the root cause difficult to diagnose.