Wiki

trigger · multiply_temp_variable

Definition

  • Supported scope:any
  • Supported target:none

Description

Multiplies a temporary variable by a value, another variable, or a [math expression](script_math_expression.md).

### Examples

multiply_temp_variable = { num_dogs = 2 } multiply_temp_variable = { num_dogs = { value = num_cats add = 1 } }

实战 · 配合 · 坑

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

实战用法

multiply_temp_variable 常用于需要在条件判断阶段对临时变量进行缩放计算的场景,例如根据某项资源数量按比例折算后再与阈值比较,或在复杂公式链中累乘系数。注意它本身作为 trigger 使用时不改变游戏状态,因此适合放在 limitavailable 块内做中间计算后配合 check_variable 做最终判断。

available = {
    # 先把临时变量设为当前工厂数量
    set_temp_variable = { var = factory_score value = num_of_factories }
    # 乘以难度系数
    multiply_temp_variable = { var = factory_score value = 0.75 }
    # 检查折算后的值是否达标
    check_variable = { factory_score > 20 }
}

配合关系

  • [set_temp_variable](/wiki/trigger/set_temp_variable) — 在乘法运算前必须先为临时变量赋初值,二者几乎总是成对出现。
  • [add_to_temp_variable](/wiki/trigger/add_to_temp_variable) — 乘法结束后常需要叠加偏移量,完成"线性变换"式的综合计算。
  • [check_variable](/wiki/trigger/check_variable) — 对乘法结果做最终数值比较,是整个计算链的收尾判断节点。
  • [divide_temp_variable](/wiki/trigger/divide_temp_variable) — 与乘法配合实现百分比换算或归一化,避免数值溢出或过大。

常见坑

  1. 忘记临时变量的作用域限制temp_variable 仅在当前 trigger/effect 块的执行生命周期内有效,跨事件或跨 scope 后值会丢失,不要期望它在下一个事件触发时还保留上次乘法的结果。
  2. 在 trigger 块中误用同名的 effect 版本multiply_temp_variable 同时存在于 effect 和 trigger 白名单,但语义相同;新手容易在 if 嵌套时混淆 trigger 上下文与 effect 上下文,导致脚本解析报错——务必确认外层块的类型再决定放置位置。

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

multiply_temp_variable is commonly used in scenarios where you need to scale a temporary variable during the condition evaluation phase, such as proportionally converting a resource quantity before comparing it against a threshold, or cumulatively multiplying coefficients in a complex formula chain. Note that when used as a trigger, it does not alter the game state, making it suitable for placement within limit or available blocks to perform intermediate calculations and then pair with check_variable for the final judgment.

available = {
    # First set the temporary variable to the current factory count
    set_temp_variable = { var = factory_score value = num_of_factories }
    # Multiply by difficulty coefficient
    multiply_temp_variable = { var = factory_score value = 0.75 }
    # Check if the scaled value meets the threshold
    check_variable = { factory_score > 20 }
}

Synergy

  • [set_temp_variable](/wiki/trigger/set_temp_variable) — The temporary variable must be initialized with a value before the multiplication operation; these two are almost always used together.
  • [add_to_temp_variable](/wiki/trigger/add_to_temp_variable) — It is common to stack an offset after multiplication to complete a "linear transformation" style composite calculation.
  • [check_variable](/wiki/trigger/check_variable) — Performs the final numerical comparison on the multiplication result and serves as the concluding judgment node of the entire calculation chain.
  • [divide_temp_variable](/wiki/trigger/divide_temp_variable) — Works in conjunction with multiplication to perform percentage conversion or normalization, preventing numerical overflow or excessive values.

Common Pitfalls

  1. Forgetting the scope limitations of temporary variables: temp_variable is only valid within the execution lifetime of the current trigger/effect block. After crossing events or scopes, the value is lost; do not expect it to retain the result of the previous multiplication when the next event is triggered.
  2. Mistakenly using the effect version with the same name in a trigger block: multiply_temp_variable exists in both effect and trigger whitelists with identical semantics; beginners often confuse trigger context with effect context during if nesting, causing script parsing errors—always confirm the type of the outer block before deciding where to place it.