trigger · if
Definition
- Supported scope:
any - Supported target:
none
Description
if_, CIfTrigger, A conditional trigger
if = { limit = { <triggers> } <trigger> }
ifanynoneif_, CIfTrigger, A conditional trigger
if = { limit = { <triggers> } <trigger> }
实战内容由 AI 生成,并已对照 vanilla 命令词表校验 —— 请当作起点而非权威依据。上方的定义节才是游戏自带文档原文。
if trigger 常用于需要在同一个条件块中根据不同情境动态决定是否满足某个条件的场景,例如在 limit 块中根据当前局势有条件地放行事件选项、科技或决策。它允许"当某些前提成立时,才追加额外判断",而不必为每种分支单独写一套完整的触发链。
# 在决策的 available 中:只有当玩家是民主国家时,才额外要求拥有同盟国战争支持
available = {
is_major = yes
if = {
limit = { has_government = democratic }
has_war_support > 0.5
}
}
[and](/wiki/trigger/and) / [or](/wiki/trigger/or) / [not](/wiki/trigger/not):if 的 limit 和主体部分都可以嵌套这些逻辑复合 trigger,用来构造复杂的分支条件;[check_variable](/wiki/trigger/check_variable):常放在 limit 中作为进入分支的变量门槛,再在主体中追加其他判断,是变量驱动逻辑的标准搭配;[custom_trigger_tooltip](/wiki/trigger/custom_trigger_tooltip):当 if 内部条件复杂时,可在同级或外层用它覆盖显示文本,避免 UI 上出现难以理解的原始条件列表;[if](/wiki/effect/if):effect 块中的同名命令与此 trigger 版语法完全平行,理解二者的区别(一个判断、一个执行)可避免在 effect 和 trigger 上下文中混用。limit 缺失时退化为恒真分支:if 在没有 limit 的情况下其主体条件始终参与判断,相当于直接把内部 trigger 写在外层,新手往往误以为省略 limit 可以"跳过"该分支,实际上结果相反。if trigger 写进 effect 块:if trigger 只在 trigger/limit/available/allowed 等条件上下文中有效;若误将其写进 immediate、option 的执行块里,应改用 effect 版的 if,两者语法相似但所处上下文不同,混淆后脚本会静默失效或报错。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.
The if trigger is commonly used in scenarios where you need to dynamically decide whether a condition is met based on different situations within the same conditional block. For example, within a limit block, you can conditionally allow event options, technologies, or decisions based on the current state. It enables "apply additional checks only when certain prerequisites are met" without requiring separate complete trigger chains for each branch.
# In a decision's available block: only if the player is a democratic nation,
# additionally require alliance war support
available = {
is_major = yes
if = {
limit = { has_government = democratic }
has_war_support > 0.5
}
}
[and](/wiki/trigger/and) / [or](/wiki/trigger/or) / [not](/wiki/trigger/not): Both the limit and main body of if can nest these logical compound triggers to construct complex branching conditions;[check_variable](/wiki/trigger/check_variable): Commonly placed in limit as a variable threshold for entering a branch, then additional checks are added in the main body; this is the standard pairing for variable-driven logic;[custom_trigger_tooltip](/wiki/trigger/custom_trigger_tooltip): When conditions inside if become complex, you can use this at the same level or outer layer to override the displayed text, preventing confusing raw condition lists from appearing in the UI;[if](/wiki/effect/if): The same-named command in effect blocks has completely parallel syntax to this trigger version. Understanding the distinction between the two (one judges, one executes) prevents mixing them up across effect and trigger contexts.if degenerates to always-true when limit is missing: When if lacks a limit, its main body conditions always participate in the evaluation, equivalent to writing the internal triggers directly at the outer level. Beginners often mistakenly think omitting limit will "skip" the branch, but the result is actually the opposite.if trigger into effect blocks: The if trigger is only valid in conditional contexts such as trigger/limit/available/allowed. If you mistakenly place it in execution blocks like immediate or option, you should use the effect version of if instead. While the syntax is similar, the context is different; confusing them causes scripts to silently fail or produce errors.