Wiki

trigger · round_temp_variable

Definition

  • Supported scope:any
  • Supported target:none

Description

Rounds a temporary variable
Example: round_temp_variable = num_dogs

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

round_temp_variable is commonly used in mod scenarios involving complex numerical calculations, such as computing population ratios, resource allocation, or percentages. It rounds floating-point results to integers to prevent decimal precision errors in subsequent comparisons or displays. A typical use case is tidying up temporary variables at the end of a numerical derivation chain in dynamic events or decisions, ensuring that subsequent check_variable logic remains clean and reliable.

# Calculate half the factory count of a state and round the result for subsequent checks
set_temp_variable = { temp_half_factories = num_factories }
divide_temp_variable = { temp_half_factories = 2 }
round_temp_variable = temp_half_factories
# After this, temp_half_factories is an integer and can be safely compared

Synergy

  • [divide_temp_variable](/wiki/effect/divide_temp_variable): Division operations almost inevitably produce decimals; rounding the result with round_temp_variable immediately afterward is the most common pairing.
  • [multiply_temp_variable](/wiki/effect/multiply_temp_variable): Multiplying by coefficients (such as percentage weights) can also yield non-integer results; rounding before passing to downstream logic is more robust.
  • [check_variable](/wiki/trigger/check_variable): Rounded temporary variables are used in conditional comparisons, avoiding unexpected judgment outcomes due to floating-point precision variance.
  • [modulo_temp_variable](/wiki/effect/modulo_temp_variable): When modulo operations require operands to have integer semantics, round_temp_variable should be applied before the modulo operation; otherwise, results may not be as expected.

Common Pitfalls

  1. Mistaking this command as an effect: round_temp_variable is used within trigger blocks and belongs to the conditional evaluation context; it cannot be placed in pure effect blocks (such as on_action, complete_effect, etc.)—those should use the same-named effect version (the whitelist also contains round_temp_variable as an effect). Confusing contexts will cause script errors or silent behavioral failures.
  2. Using the wrong command on persistent variables: round_temp_variable only operates on temp_variable (temporary variables). To round ordinary persistent variables, use [round_variable](/wiki/effect/round_variable) instead. Mixing them incorrectly will not produce a syntax error, but the data will not be modified.