Wiki

effect · get_highest_scored_country

Definition

  • Supported scope:COUNTRY
  • Supported target:none

Description

calculates the highest scored country that is defined in a country scorer and sets it to a temp variable. Example: 
get_highest_scored_country = { 
  scorer = scorer_id 
  var = var_name # temp variable name that the result will be stored. default is highest_scored_country 
}

实战 · 配合 · 坑

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

实战用法

get_highest_scored_country 常用于 AI 决策或事件脚本中,需要动态找出"得分最高"的国家并对其执行后续效果,例如选出外交压力最大的对手、最具影响力的派系成员等场景。使用时需先在 country_scorer 文件中定义好对应的 scorer 逻辑,再在 effect 块中引用。

# 找出当前得分最高的国家并存入临时变量,然后对其发出警告
country_event = {
    id = my_mod.1
    immediate = {
        get_highest_scored_country = {
            scorer = my_threat_scorer
            var = top_threat_country
        }
        var:top_threat_country = {
            country_event = { id = my_mod.2 }
        }
    }
}

配合关系

  • [get_highest_scored_country_temp](/wiki/trigger/get_highest_scored_country_temp):执行完本 effect 后,可用该 trigger 检查临时变量是否已被成功赋值(即是否存在符合条件的国家),避免对空变量操作。
  • [get_sorted_scored_countries](/wiki/effect/get_sorted_scored_countries):若需要的不只是第一名而是完整排名列表,可改用此 effect;两者底层依赖同一套 scorer 体系,逻辑上互为补充。
  • [every_other_country](/wiki/effect/every_other_country):在 scorer 难以精确筛选时,可先用此遍历所有国家配合条件累积得分数据,再由本 effect 取出最高者。
  • [add_opinion_modifier](/wiki/effect/add_opinion_modifier):取出得分最高的国家后,常立即对该国施加外交修正、宣战目标等后续效果,此命令是最典型的下游操作之一。

常见坑

  1. scorer 未正确注册就引用scorer = scorer_id 填写的 id 必须与 common/country_scores/ 下定义的 scorer 文件中的 key 完全一致,拼写错误或文件未加载会导致临时变量为空,后续所有对该变量的 scope 操作静默失败且不报错,极难排查。
  2. 误把临时变量当普通变量持久化:存储结果的 vartemp variable(临时变量),仅在当前 effect 执行链中有效,不能在事件结束后通过 check_variable 之类的触发器跨事件读取,若需持久保存需另行用 set_variable 将其转存到普通变量。

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_highest_scored_country is commonly used in AI decision-making or event scripting when you need to dynamically identify the country with the highest score and apply subsequent effects to it. Typical use cases include selecting the opponent with the greatest diplomatic pressure, the most influential faction member, and similar scenarios. When using this command, you must first define the corresponding scorer logic in a country_scorer file, then reference it in your effect block.

# Find the country with the highest current score, store it in a temporary variable, then send it a warning event
country_event = {
    id = my_mod.1
    immediate = {
        get_highest_scored_country = {
            scorer = my_threat_scorer
            var = top_threat_country
        }
        var:top_threat_country = {
            country_event = { id = my_mod.2 }
        }
    }
}

Synergy

  • [get_highest_scored_country_temp](/wiki/trigger/get_highest_scored_country_temp): After executing this effect, you can use this trigger to verify whether the temporary variable has been successfully assigned (i.e., whether a country matching the criteria exists), preventing operations on null variables.
  • [get_sorted_scored_countries](/wiki/effect/get_sorted_scored_countries): If you need not just the top result but a complete ranked list, use this effect instead; both commands rely on the same underlying scorer system and are logically complementary.
  • [every_other_country](/wiki/effect/every_other_country): When a scorer cannot precisely filter your desired countries, you can first iterate through all countries with this effect while accumulating score data based on conditions, then use this effect to extract the highest scorer.
  • [add_opinion_modifier](/wiki/effect/add_opinion_modifier): After identifying the highest-scoring country, you typically apply downstream effects such as diplomatic modifiers or war targets to that nation; this command represents one of the most common follow-up operations.

Common Pitfalls

  1. Referencing a scorer before it is properly registered: The scorer = scorer_id parameter must exactly match the key defined in the scorer file under common/country_scores/. Typos or unloaded files will result in an empty temporary variable, causing all subsequent scope operations on that variable to fail silently without error messages, making debugging extremely difficult.
  2. Treating temporary variables as persistent regular variables: The var that stores the result is a temporary variable, valid only within the current effect execution chain. It cannot be read across events after the event concludes using triggers like check_variable. If you need persistent storage, you must separately use set_variable to transfer the value to a regular variable.