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
- 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.
- 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.