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

实战 · 配合 · 坑

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

实战用法

get_sorted_scored_countries_temp 常用于需要对多个国家进行评分排名的 AI 决策或外交事件场景,例如让某国从所有潜在盟友中筛选出"最值得联盟"的国家列表,并按分数降序存储以便后续遍历处理。与普通版本 get_sorted_scored_countries 不同,此变体将结果存入临时数组,不会污染全局状态,适合在事件或 hidden_effect 中一次性使用。

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
        }
        # 此后即可用 best_ally_list[0] 取得分最高的国家
        every_country = {
            limit = { is_in_array = { array = best_ally_list value = THIS } }
            give_guarantee = ROOT
        }
    }
}

配合关系

  • [get_sorted_scored_countries_temp](/wiki/trigger/get_sorted_scored_countries_temp):同名触发器版本,可在 trigger 块中检验临时数组是否已被正确填充,常用于调试或条件判断。
  • [get_highest_scored_country_temp](/wiki/effect/get_highest_scored_country_temp):当只需要取单个得分最高国家时使用,与本 effect 互补;若需要完整排序列表才换用本命令。
  • [every_other_country](/wiki/effect/every_other_country):遍历所有其他国家时,可在循环内结合临时数组做筛选,避免对不在评分列表中的国家执行操作。
  • [country_event](/wiki/effect/country_event):通常将本 effect 置于事件的 immediate 块内,配合事件触发链完成"计算→排序→决策"的完整流程。

常见坑

  1. 忘记 scorer 字段必须提前在 common/country_scorer/ 中定义:若 scorer ID 拼写错误或文件未加载,数组会被填充为空而不会报错,导致后续逻辑静默失效,调试时需用 which = best_ally_list 配合 count_in_collection 触发器验证数组长度是否大于 0。
  2. 临时数组的作用域仅限当前效果块执行期间:temp 数组不会跨事件或跨 effect 调用持久保存,若在另一个独立事件中尝试读取同名 temp 数组将得到空值,需在同一执行上下文内完成所有对数组的读取与操作。

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.