effect · modulo_variable
Definition
- Supported scope:
any - Supported target:
none
Description
modulos a variable with another. Example:
modulo_variable = {
var = variable_to_modulo
value = divisior
}
modulo_variableanynonemodulos a variable with another. Example:
modulo_variable = {
var = variable_to_modulo
value = divisior
}
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.
modulo_variable is commonly used in mod scenarios requiring "cyclic period" logic, such as constraining a continuously accumulating counter within a specific range (e.g., week/month rotation, chessboard-style index cycling), or distributing a variable across discrete tiers in random events via modulo operation. The example below applies modulo 7 to week_counter, keeping it within the week index range of 0–6:
# Increment the counter on each event trigger, then apply modulo to maintain [0,6]
add_to_variable = { var = week_counter value = 1 }
modulo_variable = {
var = week_counter
value = 7
}
[add_to_variable](/wiki/effect/add_to_variable) — Typically paired by first accumulating the variable, then using modulo_variable to take the remainder, forming a standard "accumulate→reset cycle" pattern.[clamp_variable](/wiki/effect/clamp_variable) — If the modulo result requires additional safeguards at boundary cases (e.g., when the divisor might be 0, clamping before modulo prevents anomalous behavior), combining both improves robustness.[check_variable](/wiki/trigger/check_variable) — After taking the modulo, you typically need to read the remainder value to determine subsequent branch logic; check_variable is the most direct means of comparison.[set_variable](/wiki/effect/set_variable) — Use when initializing a variable to a definite value before modulo operation, preventing unexpected results from undefined variables.value causes script errors or undefined behavior: The game engine does not automatically skip division by zero operations. Always ensure value is non-zero before execution by using [check_variable](/wiki/trigger/check_variable) or [clamp_variable](/wiki/effect/clamp_variable).var must be an existing and assigned variable: If the target variable is never initialized via set_variable or add_to_variable before taking modulo, the remainder result is typically 0 or unpredictable. Beginners often overlook the initialization step, mistakenly believing the script executed correctly.