Wiki

trigger · 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 in loop logic that requires "execute once every N iterations," such as determining whether a counter is an integer multiple of a certain step within for_each_loop or while_loop_effect, thereby implementing batch processing or periodic checks. Typical scenarios include: performing special operations on a set of countries/provinces at fixed intervals, or using remainders to branch different outcomes in random events.

# Execute certain logic whenever loop counter i is a multiple of 3
for_loop_effect = {
    value = 0
    limit = 9
    set_temp_variable = { var = remainder value = i }
    modulo_temp_variable = { var = remainder value = 3 }
    if = {
        limit = {
            check_variable = { remainder = 0 }
        }
        # Effect only executed every 3rd iteration
        log = "[GetDateText]: every 3rd iteration"
    }
}

Synergy

  • [check_variable](/wiki/trigger/check_variable):After modulo_temp_variable computes the remainder on a temporary variable, it is almost always immediately followed by check_variable to test whether the remainder equals a target value—they are a standard pairing.
  • [set_temp_variable](/wiki/effect/set_temp_variable):Before performing the modulo operation, you must first use set_temp_variable to copy the original value into a working variable, avoiding direct modification of the source data.
  • [for_loop_effect](/wiki/effect/for_loop_effect):Provides the loop counter and serves as the outer container that triggers "periodic check" scenarios, working in tandem with modulo_temp_variable to implement execute-once-every-N-times control flow.
  • [divide_temp_variable](/wiki/effect/divide_temp_variable):When you need both quotient and remainder simultaneously, you can use it alongside modulo_temp_variable, operating on two separate temporary variables respectively.

Common Pitfalls

  1. Directly applying modulo to the source variable destroys the original valuemodulo_temp_variable modifies the variable specified by var in place. Beginners often forget to first create a copy using set_temp_variable, resulting in subsequent logic reading the remainder instead of the original counter value.
  2. A divisor (value) of 0 causes script errors:If the value field references another variable that might be zero, the game will not automatically skip it; instead, it produces a division-by-zero exception. Use check_variable before the call to ensure the divisor is nonzero.