Wiki

trigger · divide_temp_variable

Definition

  • Supported scope:any
  • Supported target:none

Description

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

### Examples

divide_temp_variable = { num_dogs = 2 } divide_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

divide_temp_variable is commonly used in complex numerical logic that requires calculating averages, ratios, or percentages—such as computing per-capita factory counts, casualty ratios, or resource distribution proportions. It performs division on temporary variables within trigger conditional blocks, typically combined with other mathematical triggers to complete multi-step calculations before making a final judgment using check_variable.

# Check whether a country's factory count reaches an average of 1.5+ per owned state
set_temp_variable = { var = factory_ratio value = num_factories_mio }
divide_temp_variable = { var = factory_ratio value = num_owned_states }
check_variable = { factory_ratio > 1.5 }

Synergy

  • [set_temp_variable](/wiki/trigger/set_temp_variable): The temporary variable must be initialized with a value before division; otherwise the variable referenced by divide_temp_variable is undefined and results are unpredictable.
  • [multiply_temp_variable](/wiki/trigger/multiply_temp_variable): Often used in conjunction before or after division—for example, multiplying by 100 before dividing by a base value to convert fractional results into integer percentages for easier comparison.
  • [check_variable](/wiki/trigger/check_variable): Division itself does not produce a true/false result; you must use check_variable to apply threshold judgment to the calculation result for it to have practical effect in a conditional block.
  • [clamp_temp_variable](/wiki/trigger/clamp_temp_variable): Division may produce extreme values outside the expected range (especially when the divisor is very small); use clamp_temp_variable to constrain the result within a safe interval and prevent subsequent logic errors.

Common Pitfalls

  1. Division by zero causes script errors or abnormal results: When the divisor variable (referenced by the value parameter) could be 0 at runtime—such as a newly founded country with zero owned states—you must check that the divisor is non-zero using check_variable or if before executing divide_temp_variable. Failure to do so will cause script errors or even game crashes.
  2. Mistakenly using it as an effect: divide_temp_variable exists in both the trigger and effect whitelists, which often confuses newcomers. Within trigger/limit blocks, it only modifies the temporary variable to assist condition evaluation and does not persistently alter any game state. Attempting to use it within a trigger block as a "side-effect assignment" to influence subsequent effects is ineffective; actual value modifications must be performed in effect blocks.