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

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.