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
- 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.
- 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.