Wiki

effect · randomize_temp_variable

Definition

  • Supported scope:any
  • Supported target:none

Description

Randomize a temporary variable
randomize_temp_variable = num_dogs
# which is equivalient to
randomize_temp_variable = {
  var = num_dogs
  distribution = uniform
}
# which is equivalent to
randomize_temp_variable = {
  var = num_dogs
  distribution = uniform
  min = 0
  max = 1
}
# also allow for binomial distribution (with N=2)randomize_temp_variable = {
  var = num_dogs
  distribution = binomial
  min = 0               # optional
  max = 10              # required if min is specified
}
# also allow for the poisson distributionrandomize_temp_variable = {
  var = num_dogs
  distribution = poisson
  lambda = 10           # required
  min = 10              # optional
}

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

randomize_temp_variable is commonly used in event outcomes that require introducing randomness, such as randomizing battle casualties, generating random resource reward amounts, or determining random event branch weights. Compared to hardcoding fixed values, it makes mod results more unpredictable and enhances gameplay experience.

# Randomly generate a political power reward in an event option (uniform distribution between 0~5)
option = {
    name = my_event.option_a
    randomize_temp_variable = {
        var = temp_pp_gain
        distribution = uniform
        min = 0
        max = 5
    }
    round_temp_variable = temp_pp_gain
    add_political_power = temp_pp_gain
}

Synergy

  • [round_temp_variable](/wiki/effect/round_temp_variable): The uniform distribution produces floating-point numbers; you typically need to round first before passing to integer-only effects (such as add_political_power), otherwise unexpected behavior may occur.
  • [clamp_temp_variable](/wiki/effect/clamp_temp_variable): After generating a random value, use clamp to constrain it within the safe range permitted by your game logic, preventing extreme values from breaking balance.
  • [add_to_temp_variable](/wiki/effect/add_to_temp_variable): Stack a fixed offset on top of the randomized base value to implement the common "random value + guaranteed minimum" design pattern.
  • [check_variable](/wiki/trigger/check_variable): After randomization, you typically need to branch execution based on the result; pair with check_variable inside if blocks to test which interval the random result falls into.

Common Pitfalls

  1. Forgetting to round the result: The uniform distribution produces floating-point numbers by default. If you pass temp_variable directly to effects that only accept integers (such as add_manpower), the script won't error but will silently truncate or produce unexpected values—always call round_temp_variable first.
  2. Omitting max in binomial / lambda in poisson: binomial requires max to be specified when min is set; poisson always requires lambda. Omitting these fields won't produce obvious error messages, but distribution parameters will revert to default behavior, causing random results to be completely misaligned with your expectations.