命令百科

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 数组将得到空值,需在同一执行上下文内完成所有对数组的读取与操作。