Wiki

trigger · date

Definition

  • Supported scope:any
  • Supported target:none

Description

checks for a specific date

实战 · 配合 · 坑

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

实战用法

date 常用于限制某些决策、事件或聚焦的触发窗口,例如只允许在特定历史日期之后解锁某条科技或开启战争借口。在替代历史 mod 中,也常用它来区分"历史阶段",确保剧情事件在正确的时间轴节点触发。

# 某个决策的 available 块:1942年6月6日之后才可用
available = {
    date > 1942.6.6
    has_war = yes
}

配合关系

  • [has_start_date](/wiki/trigger/has_start_date)has_start_date 检查存档的开局日期,与 date 搭配可区分"开局时间"和"当前游戏时间",避免逻辑混淆。
  • [or](/wiki/trigger/or) / [and](/wiki/trigger/and):将多个 date 条件组合,构造"时间窗口"(某日之后且某日之前),是限定事件触发区间的标准写法。
  • [custom_trigger_tooltip](/wiki/trigger/custom_trigger_tooltip)date 条件本身的 UI 提示有时不够直观,用 custom_trigger_tooltip 包裹后可显示更友好的本地化文本给玩家。
  • [if](/wiki/effect/if) / [if](/wiki/trigger/if):在 if 块的 limit 中嵌套 date,实现"到达某日期后执行不同分支"的动态逻辑。

常见坑

  1. 比较方向写反date > 1939.9.1 表示"当前日期晚于1939年9月1日",新手常误写为 date < 1939.9.1 想表达"已经到了这个日期",结果逻辑完全相反,导致条件永远不满足或提前触发。
  2. 日期格式错误:HOI4 脚本要求日期格式严格为 YYYY.M.D(如 1941.12.7),误写成 1941-12-071941/12/7 会导致解析失败,且游戏通常不会给出明显报错,只是条件静默失效。

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

date is commonly used to restrict the trigger window for certain decisions, events, or focuses—for example, allowing a technology to be unlocked or a war justification to be initiated only after a specific historical date. In alternate history mods, it is also frequently used to distinguish "historical periods" and ensure story events trigger at the correct point on the timeline.

# available block in a decision: only available after June 6, 1942
available = {
    date > 1942.6.6
    has_war = yes
}

Synergy

  • [has_start_date](/wiki/trigger/has_start_date): has_start_date checks the save game's start date. When paired with date, it helps distinguish between "initial game date" and "current game date," preventing logical confusion.
  • [or](/wiki/trigger/or) / [and](/wiki/trigger/and): Combining multiple date conditions constructs a "time window" (after date X and before date Y), which is the standard approach for restricting event trigger intervals.
  • [custom_trigger_tooltip](/wiki/trigger/custom_trigger_tooltip): The UI tooltip for date conditions is sometimes not intuitive enough. Wrapping it with custom_trigger_tooltip allows you to display more user-friendly localized text to players.
  • [if](/wiki/effect/if) / [if](/wiki/trigger/if): Nesting date within the limit block of an if statement enables "execute different branches after reaching a certain date" dynamic logic.

Common Pitfalls

  1. Comparison direction reversed: date > 1939.9.1 means "current date is later than September 1, 1939." Beginners often mistakenly write date < 1939.9.1 intending to express "this date has been reached," resulting in completely inverted logic that causes conditions to never be satisfied or trigger prematurely.
  2. Incorrect date format: HOI4 scripts strictly require the date format YYYY.M.D (e.g., 1941.12.7). Writing it as 1941-12-07 or 1941/12/7 causes parsing to fail. The game typically provides no obvious error message and simply silently invalidates the condition.