Wiki

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 不会报错但数组将为空,排查时很难发现根源。

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 diplomatic decisions or events when you need to sort all countries by a custom score (such as threat level, opinion, or military strength) and access a specific ranked country. For example, in a decision to "find the best ally target," use this trigger to sort candidate countries by a custom scoring function, then iterate through the temporary array:

available = {
    get_sorted_scored_countries_temp = {
        scorer = best_ally_scorer
        array = candidate_countries
        scores = candidate_scores
    }
    # After sorting, the array can be used in the same trigger block or subsequent effects
    count_in_collection = {
        array = candidate_countries
        count > 0
    }
}

Synergy

  • [get_highest_scored_country_temp](/wiki/trigger/get_highest_scored_country_temp): After sorting the complete list, if you only need the single highest-scoring country, use this trigger to directly fetch the top entry. The two triggers complement each other logically.
  • [count_in_collection](/wiki/trigger/count_in_collection): Validates that the array actually contains valid countries after sorting, preventing logic errors from operating on empty arrays.
  • [get_sorted_scored_countries](/wiki/effect/get_sorted_scored_countries): The effect version corresponds semantically to this trigger. Use it when you need to execute the same sorting operation within an effect block. Both share identical parameter structures and can be cross-referenced.
  • [get_highest_scored_country_temp](/wiki/effect/get_highest_scored_country_temp): Retrieves the highest-scoring country after sorting and stores it in a temporary variable on the effect side. Commonly paired with this trigger in the available/effect workflow.

Common Pitfalls

  1. Assuming arrays persist across scopes: The _temp suffix means the array only lives within the current scope or event execution cycle. You cannot reference it across scopes or between events after this trigger completes. Beginners often copy temporary array names into effect blocks expecting persistent storage, only to find the data is already invalid.
  2. Forgetting that scorer must be registered in country_scorer: The id specified in scorer = xxx must have a corresponding definition in the common/country_scorer/ folder. Entering a non-existent id won't cause an error, but the array will be empty, making the root cause difficult to diagnose.