Wiki

effect · get_sorted_scored_countries_temp

Definition

  • Supported scope:COUNTRY
  • Supported target:none

Description

calculates & sorts all countries in a country scorer and stores them and their scores in temp arrays. Example: 
get_sorted_scored_countries_temp = { 
  scorer = scorer_id # id that is used in country scorer  array = array_name # a name to store sorted countries as a temp array (default to sorted_country_list) 
  scores = array_name # corresponding score temp 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_temp is commonly used in AI decision-making or diplomatic event scenarios where you need to score and rank multiple countries. For example, it lets a country filter all potential allies to identify the "most worthy alliance candidates" and store them in descending score order for subsequent iteration. Unlike the standard get_sorted_scored_countries variant, this version stores results in a temporary array, avoiding pollution of global state and making it ideal for one-time use within events or hidden_effect blocks.

country_event = {
    id = my_mod.1
    hidden = yes
    immediate = {
        get_sorted_scored_countries_temp = {
            scorer = my_ally_scorer
            array = best_ally_list
            scores = best_ally_scores
        }
        # Now you can retrieve the highest-scoring country via best_ally_list[0]
        every_country = {
            limit = { is_in_array = { array = best_ally_list value = THIS } }
            give_guarantee = ROOT
        }
    }
}

Synergy

  • [get_sorted_scored_countries_temp](/wiki/trigger/get_sorted_scored_countries_temp): Corresponding trigger version that validates whether the temporary array has been correctly populated within a trigger block; useful for debugging or conditional checks.
  • [get_highest_scored_country_temp](/wiki/effect/get_highest_scored_country_temp): Use when you only need a single highest-scoring country; complements this effect, and switch to this command only if you require the complete sorted list.
  • [every_other_country](/wiki/effect/every_other_country): When iterating over all other countries, you can combine filtering with temporary arrays inside the loop to avoid executing operations on countries not in the scoring list.
  • [country_event](/wiki/effect/country_event): Typically place this effect within an event's immediate block, paired with event trigger chains to complete the full "calculate → sort → decide" workflow.

Common Pitfalls

  1. Forgetting that the scorer field must be defined in advance in common/country_scorer/: If the scorer ID is misspelled or the file fails to load, the array will be silently populated as empty without error messages, causing subsequent logic to fail silently. During debugging, use which = best_ally_list combined with the count_in_collection trigger to verify that the array length is greater than 0.
  2. Temporary arrays only persist during the current effect block execution: Temp arrays do not carry over across events or effect calls; if you attempt to read the same-named temp array in another independent event, you will get empty values. All array reads and operations must be completed within the same execution context.