Wiki

effect · get_sorted_scored_countries

Definition

  • Supported scope:COUNTRY
  • Supported target:none

Description

calculates & sorts all countries in a country scorer and stores them and their scores in arrays. Example: 
get_sorted_scored_countries = { 
  scorer = scorer_id # id that is used in country scorer  array = array_name # a name to store sorted countries as an array (default to sorted_country_list) 
  scores = array_name # corresponding score array for countries stored in array (default to country_list_scores) 
}

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

get_sorted_scored_countries is commonly used in AI diplomatic decisions, alliance evaluations, or event triggers when you need to sort all countries by some weighting criteria (military strength, ideological alignment, threat level, etc.) and process them in bulk. For example, in a diplomatic mod where you want to identify the top-scoring potential allies, you would first use this effect to generate a sorted array, then combine it with loops to process each country individually:

# In the immediate block of a country event
immediate = {
    get_sorted_scored_countries = {
        scorer = my_alliance_scorer
        array  = potential_allies
        scores = potential_allies_scores
    }
    # After this, you can use the potential_allies / potential_allies_scores arrays for subsequent operations
}

Synergy

  • [get_highest_scored_country](/wiki/effect/get_highest_scored_country): If you only need the top-ranked country without requiring the full array, use this command as a lightweight alternative; both share the same scorer framework and are logically complementary.
  • [get_sorted_scored_countries_temp](/wiki/effect/get_sorted_scored_countries_temp): Temporary version where the array is only valid within the current effect block scope, suitable when you don't need persistent arrays and want to avoid polluting the global variable space.
  • [every_other_country](/wiki/effect/every_other_country): After generating a sorted array, commonly combined with this loop to execute diplomatic or state-change operations on each country in the array sequentially.
  • [get_sorted_scored_countries_temp](/wiki/trigger/get_sorted_scored_countries_temp): Used on the trigger side to verify whether the sorted results meet expected conditions, forming a complete trigger-execution loop with the effect side.

Common Pitfalls

  1. The scorer ID must be defined in advance in common/country_scoring/: If scorer = xxx references a non-existent scorer, the game will not produce an obvious error, but the array will be empty and all subsequent logic depending on that array will fail silently—extremely difficult to debug.
  2. Default array names easily cause naming collisions: Both the array and scores parameters have default names. If you call this effect multiple times in the same event chain without explicitly specifying different array names, the later call will directly overwrite the previous result, causing data loss.