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) 
}

实战 · 配合 · 坑

实战内容由 AI 生成,并已对照 vanilla 命令词表校验 —— 请当作起点而非权威依据。上方的定义节才是游戏自带文档原文。

实战用法

get_sorted_scored_countries 常用于 AI 外交决策、结盟评估或事件触发时,需要对所有国家按某种权重(军事实力、意识形态契合度、威胁值等)排序并批量处理的场景。例如在一个外交 mod 中,想找出得分最高的若干潜在盟友,先用此 effect 生成排序数组,再配合循环逐一处理:

# 在某个 country event 的 immediate 块中
immediate = {
    get_sorted_scored_countries = {
        scorer = my_alliance_scorer
        array  = potential_allies
        scores = potential_allies_scores
    }
    # 此后即可用 potential_allies / potential_allies_scores 两个数组做后续操作
}

配合关系

  • [get_highest_scored_country](/wiki/effect/get_highest_scored_country):若只需取排序第一的国家而不需要完整数组,可用此命令作为轻量替代;两者共用同一套 scorer 体系,逻辑上互为补充。
  • [get_sorted_scored_countries_temp](/wiki/effect/get_sorted_scored_countries_temp):临时版本,数组仅在当前 effect 块作用域内有效,适合不需要持久化数组时使用,避免污染全局变量空间。
  • [every_other_country](/wiki/effect/every_other_country):在生成排序数组后,常结合此循环对数组中每个国家依次执行外交或状态改变操作。
  • [get_sorted_scored_countries_temp](/wiki/trigger/get_sorted_scored_countries_temp):在 trigger 侧判断排序结果是否符合预期条件时使用,与 effect 侧形成触发-执行的完整闭环。

常见坑

  1. scorer ID 必须事先在 common/country_scoring/ 中定义好,如果 scorer = xxx 引用了不存在的 scorer,游戏不会报明显错误,但数组将为空,后续所有依赖该数组的逻辑会静默失效,极难排查。
  2. 数组名默认值容易产生命名冲突arrayscores 参数均有默认名,若同一事件链中多次调用此 effect 却不显式指定不同的数组名,后一次调用会直接覆盖前一次的结果,导致数据丢失。

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.