Wiki

trigger · meta_trigger

Definition

  • Supported scope:STATE, COUNTRY, CHARACTER, COMBATANT, ACE, STRATEGIC_REGION, OPERATION, INDUSTRIAL_ORG, PURCHASE_CONTRACT, RAID_INSTANCE, SPECIAL_PROJECT, FACTION
  • Supported target:THIS, ROOT, PREV, FROM, OWNER, CONTROLLER, OCCUPIED, CAPITAL

Description

meta triggers can be used for building triggers from strings and running them. following example will test if Germany has 42 pp:
meta_trigger = {
    text = {
        [COUNTRY] = {
            political_power > [POW]
        }
    }
    COUNTRY = "GER"
    POW = 42
    debug = no #set to yes if you want to see what game actually executes
}

实战 · 配合 · 坑

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

实战用法

meta_trigger 适合在通用模板脚本中构建动态条件——例如做一个"任意国家达到某阈值"的复用判断框架,或者在 scripted_trigger 里根据变量动态拼接国家 tag 进行判断,而无需为每个国家硬写重复代码。以下示例检测变量指定的国家是否拥有某项科技:

# 判断 TARGET_TAG 指向的国家是否已研究 TARGET_TECH
meta_trigger = {
    text = {
        [NATION] = {
            has_tech = [TECH]
        }
    }
    NATION = "GER"
    TECH = "infantry_weapons2"
    debug = no
}

配合关系

  • [hidden_trigger](/wiki/trigger/hidden_trigger):将 meta_trigger 包裹在 hidden_trigger 内,可避免动态构建的条件以难以阅读的形式暴露在本地化提示中,保持 UI 整洁。
  • [any_country_with_core](/wiki/trigger/any_country_with_core):常与 meta_trigger 配合遍历场景,当需要对动态集合中的每个成员执行参数化判断时,两者嵌套使用可极大减少重复代码。
  • [has_dynamic_modifier](/wiki/trigger/has_dynamic_modifier):动态 modifier 的存在往往依赖运行时变量,与 meta_trigger 一起使用可将动态 modifier 的检查条件本身也参数化,统一由字符串模板驱动。

常见坑

  1. 占位符大小写必须完全一致text 块中 [COUNTRY] 与下方赋值键 COUNTRY = 的字符串必须逐字母匹配,任何大小写差异都会导致替换静默失败,条件永远返回假,且不会产生明显报错。
  2. text 块内写的是目标 scope 的 trigger,而非当前 scope:初学者容易把外层 scope 的判断逻辑直接写进 text,忘记 [COUNTRY] = { ... } 已经切换了 scope,导致在错误的对象上执行条件判断,逻辑结果完全偏离预期。

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

meta_trigger is ideal for constructing dynamic conditions in generic template scripts—for example, building a reusable judgment framework for "any country reaching a certain threshold," or dynamically concatenating country tags within a scripted_trigger based on variables without hardcoding repetitive logic for each nation. The following example checks whether a country specified by a variable possesses a particular technology:

# Check if the country pointed to by TARGET_TAG has researched TARGET_TECH
meta_trigger = {
    text = {
        [NATION] = {
            has_tech = [TECH]
        }
    }
    NATION = "GER"
    TECH = "infantry_weapons2"
    debug = no
}

Synergy

  • [hidden_trigger](/wiki/trigger/hidden_trigger): Wrapping meta_trigger inside hidden_trigger prevents dynamically constructed conditions from exposing themselves in hard-to-read form within localization tooltips, keeping the UI clean.
  • [any_country_with_core](/wiki/trigger/any_country_with_core): Often paired with meta_trigger for scenario traversal; when you need to execute parameterized judgments on each member of a dynamic set, nesting the two together dramatically reduces redundant code.
  • [has_dynamic_modifier](/wiki/trigger/has_dynamic_modifier): The existence of dynamic modifiers often depends on runtime variables; using it alongside meta_trigger allows the conditions for checking dynamic modifiers themselves to be parameterized, all driven uniformly by string templates.

Common Pitfalls

  1. Placeholder casing must match exactly: The [COUNTRY] in the text block and the assignment key COUNTRY = below must match letter-for-letter. Any case difference will cause the substitution to fail silently, the condition will always return false, and no obvious error will be raised.
  2. The text block contains triggers for the target scope, not the current scope: Beginners often write judgment logic for the outer scope directly into text, forgetting that [COUNTRY] = { ... } has already switched the scope, resulting in executing conditions on the wrong object and producing completely unexpected logic results.