Wiki

trigger · exists

Definition

  • Supported scope:COUNTRY
  • Supported target:none

Description

Check if the current country exist. The country of the scope you are in. Example: DEN = { exists = yes }

实战 · 配合 · 坑

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

实战用法

exists 常用于国家事件或决策的 trigger/available 块中,防止脚本对已经被消灭(不存在)的国家进行操作,避免出现空指针错误或逻辑异常。例如在一个"邀请盟友加入阵营"的决策里,先确认目标国仍然存在再执行后续判断:

available = {
    GER = { exists = yes }
    GER = { is_in_faction = no }
}

配合关系

  • [has_capitulated](/wiki/trigger/has_capitulated):投降国在技术上可能仍"存在",配合使用可区分"存在但已投降"与"彻底亡国"两种状态,逻辑更严谨。
  • [any_allied_country](/wiki/trigger/any_allied_country):遍历盟友时嵌套 exists = yes 作为过滤条件,确保循环内的每个盟友都是有效国家。
  • [annex_country](/wiki/effect/annex_country):在执行吞并前先用 exists = yes 做前置检查,防止对已不存在的国家标签执行吞并导致脚本报错。
  • [country_event](/wiki/effect/country_event):向特定国家发送事件前确认其存在,避免事件发往已灭亡的国家标签而静默失败。

常见坑

  1. 混淆"存在"与"未投降"exists = yes 只检查国家标签是否仍在游戏中注册,已投降但未被吞并的国家依然返回 true,若需排除投降国需额外搭配 has_capitulated = no
  2. 在 effect 块中误用:新手有时将 exists 写进 effect(效果)块,例如直接放在 country_eventimmediate 里,这会导致脚本解析报错——exists 是纯判断 trigger,只能出现在条件块中。

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

exists is commonly used in the trigger/available blocks of country events or decisions to prevent scripts from operating on eliminated (non-existent) nations, avoiding null pointer errors or logic failures. For example, in a decision like "invite allies to join faction", first confirm the target nation still exists before executing subsequent checks:

available = {
    GER = { exists = yes }
    GER = { is_in_faction = no }
}

Synergy

  • [has_capitulated](/wiki/trigger/has_capitulated): Capitulated nations technically may still "exist"; using these together can distinguish between "exists but capitulated" and "completely annihilated" states, making logic more robust.
  • [any_allied_country](/wiki/trigger/any_allied_country): When iterating through allies, nest exists = yes as a filter condition to ensure each ally in the loop is a valid nation.
  • [annex_country](/wiki/effect/annex_country): Perform a preliminary check with exists = yes before executing annexation to prevent script errors from trying to annex non-existent country tags.
  • [country_event](/wiki/effect/country_event): Confirm a nation's existence before sending it an event, avoiding silent failures when events are sent to eliminated country tags.

Common Pitfalls

  1. Confusing "exists" with "not capitulated": exists = yes only checks whether the country tag is still registered in the game; nations that have capitulated but not been annexed still return true. If you need to exclude capitulated nations, you must additionally combine it with has_capitulated = no.
  2. Misusing in effect blocks: Newcomers sometimes place exists in effect blocks, such as directly putting it in the immediate section of a country_event, causing script parsing errors—exists is a pure trigger check and can only appear in conditional blocks.