Wiki

trigger · debug_math_expr

Definition

  • Supported scope:any
  • Supported target:any

Description

Evaluates a math expression and writes the numeric result to the tooltip.

Always returns true and is intended for debugging scripts.

### Parameters
- `Expression`: Any supported math expression.

### Example

debug_math_expr = { value = 120 add = 15 clamp = { min = 0 max = 100 } }

实战 · 配合 · 坑

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

实战用法

debug_math_expr 主要用于 mod 开发调试阶段,帮助作者在鼠标悬停提示中实时查看复杂数学表达式的计算结果,例如验证变量运算逻辑是否符合预期。它在 trigger 块中永远返回 true,因此可以安全地嵌入任何条件判断链而不影响游戏逻辑。

# 在某 decision 的 available 块中调试一个经过加减与钳位的变量表达式
available = {
    debug_math_expr = {
        value = var:my_resource_var
        add = 20
        clamp = { min = 0  max = 100 }
    }
    check_variable = { var:my_resource_var > 10 }
}

配合关系

  • check_variable:最常见搭档,先用 debug_math_expr 在 tooltip 中打印中间值,再用 check_variable 做实际的条件判断,方便对比理论值与判断阈值。
  • log:在 debug 模式下同步将信息写入日志文件,与 debug_math_expr 配合可同时在 UI 和日志两端留下调试痕迹。
  • is_debug:用 is_debug 将整个调试块包裹在 if 条件内,确保 debug_math_expr 只在调试模式下生效,正式发布时不污染玩家 tooltip。
  • set_temp_variable:在 effect 侧将复杂运算结果暂存到临时变量,再在 trigger 侧用 debug_math_expr 验证该临时变量的最终数值是否落在预期区间。

常见坑

  1. 误以为可以用于正式逻辑判断debug_math_expr 永远返回 true,无论表达式结果如何,不能用它替代 check_variable 来实现"当计算值满足条件时才通过"的逻辑,否则条件将无条件放行。
  2. 发布版本未移除或未用 is_debug 包裹:该 trigger 会在所有玩家的 tooltip 中显示原始数值,若正式发布的 mod 中遗留了裸露的 debug_math_expr,会让玩家看到内部调试数字,影响体验且可能暴露 mod 的内部变量结构。

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

debug_math_expr is primarily used during mod development and debugging. It lets authors inspect the computed result of complex math expressions in real time via tooltip hover, making it easy to verify that variable arithmetic behaves as expected. Because it always returns true inside a trigger block, it can be safely embedded anywhere in a condition chain without affecting game logic.

# Debugging a variable expression with addition and clamping inside a decision's available block
available = {
    debug_math_expr = {
        value = var:my_resource_var
        add = 20
        clamp = { min = 0  max = 100 }
    }
    check_variable = { var:my_resource_var > 10 }
}

Synergy

  • check_variable: The most common pairing. Use debug_math_expr to print intermediate values in the tooltip, then use check_variable for the actual condition check — making it easy to compare the theoretical value against the decision threshold.
  • log: In debug mode, writes information to the log file simultaneously. Combining this with debug_math_expr leaves debug traces in both the UI tooltip and the log at the same time.
  • is_debug: Wrap the entire debug block in an if condition using is_debug to ensure debug_math_expr only fires in debug mode, preventing it from cluttering player tooltips in a public release.
  • set_temp_variable: On the effect side, store the result of a complex calculation in a temporary variable, then use debug_math_expr on the trigger side to verify that the temporary variable's final value falls within the expected range.

Common Pitfalls

  1. Mistaking it for a real condition check: debug_math_expr always returns true regardless of the expression's result. It cannot replace check_variable to implement logic like "only pass when the computed value meets a condition" — using it that way will cause the condition to pass unconditionally.
  2. Leaving it in release builds without is_debug wrapping: This trigger displays raw internal values in every player's tooltip. If a bare debug_math_expr is left in a publicly released mod, players will see internal debug numbers, degrading the experience and potentially exposing the mod's internal variable structure.