Wiki

effect · modulo_temp_variable

Definition

  • Supported scope:any
  • Supported target:none

Description

modulos a temp variable with another. Example: 
modulo_temp_variable = { 
  var = variable_to_modulo 
  value = divisior 
}

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

modulo_temp_variable is commonly used for loop counting, periodic checks, or constraining values within a specific range—for example, triggering an event every N days, or mapping random values to fixed intervals. It's also highly practical for procedurally generating content such as grouping map tile indices or cycling through country list indices.

# Example: Check if the current loop counter is a multiple of 3
set_temp_variable = { var = remainder value = counter }
modulo_temp_variable = { var = remainder value = 3 }
if = {
    limit = { check_variable = { var = remainder value = 0 } }
    # Logic that executes once every 3 iterations
    add_to_variable = { var = milestone_count value = 1 }
}

Synergy

  • [set_temp_variable](/wiki/effect/set_temp_variable) — Assign or copy the target variable before the modulo operation to avoid modifying the original variable directly.
  • [add_to_temp_variable](/wiki/effect/add_to_temp_variable) — Pair with a counter; increment it each loop iteration and then apply modulo to implement periodic trigger logic.
  • [check_variable](/wiki/trigger/check_variable) — The modulo result is typically checked immediately with this trigger to determine whether the remainder equals 0 (or an expected value) and branch accordingly.
  • [for_loop_effect](/wiki/effect/for_loop_effect) — Often combined with modulo inside the loop body for grouping operations—for example, applying modulo to the loop index by group count to assign different behaviors.

Common Pitfalls

  1. Applying modulo directly to the original variable causes data loss: modulo_temp_variable modifies the variable specified by var in place. If you apply it directly to a business-critical counter variable, the original value is overwritten by the remainder. Instead, first use set_temp_variable to copy the value to a temporary intermediate variable, then apply modulo to that intermediate variable.
  2. Division by zero (value = 0) causes script failure: If the value field resolves to 0 at runtime, it triggers a division-by-zero error that silently fails the effect or throws an error. When value comes from a dynamic variable, always use [check_variable](/wiki/trigger/check_variable) or [clamp_temp_variable](/wiki/effect/clamp_temp_variable) to ensure it is greater than 0.