Wiki

effect · multiply_temp_variable

Definition

  • Supported scope:any
  • Supported target:none

Description

Multiplies a temp 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 常用于动态伤害/奖励计算场景,例如根据某个基础值乘以倍率得到最终结果,再赋予到国家或状态上。典型场景包括:按科技等级缩放生产加成、按人口比例计算征兵数量等。

# 计算最终援助物资数量 = 基础量 × 战争支持度系数
set_temp_variable = { var = aid_amount value = 500 }
set_temp_variable = { var = war_support_ratio value = ROOT.war_support }
divide_temp_variable = { var = war_support_ratio value = 100 }
multiply_temp_variable = { var = aid_amount value = war_support_ratio }
add_to_variable = { var = stored_aid value = aid_amount }

配合关系

  • [set_temp_variable](/wiki/effect/set_temp_variable):在做乘法之前必须先用它初始化临时变量,否则变量无初始值,乘法结果不可预期。
  • [add_to_temp_variable](/wiki/effect/add_to_temp_variable) / [subtract_from_temp_variable](/wiki/effect/subtract_from_temp_variable):乘法通常是多步算式的中间环节,前后往往需要加减操作来完成完整公式。
  • [check_variable](/wiki/trigger/check_variable):乘法计算完成后,常用此触发器检验结果是否落在合理区间,再决定后续分支逻辑。
  • [clamp_temp_variable](/wiki/effect/clamp_temp_variable):对乘法结果进行上下限截断,防止数值溢出或产生游戏性失衡。

常见坑

  1. 忘记临时变量的生命周期temp variable 仅在当前效果块执行期间存在,跨 event option 或跨 on_action 后就会消失,不要期望它在下一个触发点还保有乘法结果,需持久化时应改用 [set_variable](/wiki/effect/set_variable) 存到普通变量。
  2. 直接对未初始化变量做乘法:如果目标变量此前从未被 set_temp_variable 赋值,其初始值为 0,任何数乘以 0 仍为 0,导致结果始终归零且极难排查——务必在乘法前确认变量已被赋予有效初始值。

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 dynamic damage/reward calculation scenarios, such as computing a final result by multiplying a base value by a scaling factor, then assigning it to a country or state. Typical use cases include scaling production bonuses by technology level and calculating recruitment numbers based on population ratios.

# Calculate final aid quantity = base amount × war support coefficient
set_temp_variable = { var = aid_amount value = 500 }
set_temp_variable = { var = war_support_ratio value = ROOT.war_support }
divide_temp_variable = { var = war_support_ratio value = 100 }
multiply_temp_variable = { var = aid_amount value = war_support_ratio }
add_to_variable = { var = stored_aid value = aid_amount }

Synergy

  • [set_temp_variable](/wiki/effect/set_temp_variable): You must initialize the temporary variable with this before performing multiplication, otherwise the variable has no initial value and the multiplication result becomes unpredictable.
  • [add_to_temp_variable](/wiki/effect/add_to_temp_variable) / [subtract_from_temp_variable](/wiki/effect/subtract_from_temp_variable): Multiplication is typically an intermediate step in multi-step formulas, often requiring addition and subtraction operations before and after to complete the full calculation.
  • [check_variable](/wiki/trigger/check_variable): After multiplication is complete, this trigger is commonly used to verify whether the result falls within a reasonable range before deciding on subsequent branching logic.
  • [clamp_temp_variable](/wiki/effect/clamp_temp_variable): Apply upper and lower bounds clamping to the multiplication result to prevent numerical overflow or create gameplay imbalances.

Common Pitfalls

  1. Forgetting the lifespan of temporary variables: temp variable only exists during the execution of the current effect block. After crossing event option boundaries or on_action triggers, it disappears. Do not expect it to retain the multiplication result at the next trigger point. For persistent storage, use [set_variable](/wiki/effect/set_variable) to store the value in a regular variable instead.
  2. Performing multiplication on uninitialized variables: If the target variable has never been assigned a value via set_temp_variable, its initial value is 0. Any number multiplied by 0 remains 0, causing the result to always be zero and making it extremely difficult to debug. Always confirm the variable has been assigned a valid initial value before performing multiplication.