命令百科

trigger · 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 外交决策或事件中,需要按某种评分(如威胁度、好感度、实力)对所有国家排序并取其中特定名次国家时使用。例如在一个"寻找最佳结盟目标"的决策中,先用此 trigger 将候选国按自定义评分排好序,再通过临时数组逐一访问:

available = {
    get_sorted_scored_countries_temp = {
        scorer = best_ally_scorer
        array = candidate_countries
        scores = candidate_scores
    }
    # 排序完成后数组可在同一 trigger 块或后续 effect 中使用
    count_in_collection = {
        array = candidate_countries
        count > 0
    }
}

配合关系

  • [get_highest_scored_country_temp](/wiki/trigger/get_highest_scored_country_temp):排序完整列表后,若只需要取分数最高的单个国家,可配合此 trigger 直接获取头名,逻辑互补。
  • [count_in_collection](/wiki/trigger/count_in_collection):用于在排序后验证数组中实际存入了有效国家,避免对空数组做后续操作导致逻辑错误。
  • [get_sorted_scored_countries](/wiki/effect/get_sorted_scored_countries):effect 版本与本 trigger 语义对应,需要在 effect 块中执行相同排序操作时使用它,两者参数结构一致,配合阅读可互相参照。
  • [get_highest_scored_country_temp](/wiki/effect/get_highest_scored_country_temp):在 effect 侧取出排序后分数最高的国家并存入临时变量,常与本 trigger 在 available/effect 分工中搭配使用。

常见坑

  1. 误以为数组在跨作用域可用_temp 后缀意味着数组仅存活于当前作用域/事件执行周期,不能在本次 trigger 计算结束后跨 scope 或跨事件引用,新手常把临时数组名写入 effect 块期望持久保留,结果数据已失效。
  2. 忘记 scorer 必须已在 country_scorer 中注册scorer = xxx 的 id 必须在 common/country_scorer/ 文件夹下有对应定义,直接填写一个不存在的 id 不会报错但数组将为空,排查时很难发现根源。