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
}
modulo_temp_variableanynonemodulos a temp variable with another. Example:
modulo_temp_variable = {
var = variable_to_modulo
value = divisior
}
实战内容由 AI 生成,并已对照 vanilla 命令词表校验 —— 请当作起点而非权威依据。上方的定义节才是游戏自带文档原文。
modulo_temp_variable 常用于需要"每隔 N 次触发一次"的循环逻辑,例如在 for_each_loop 或 while_loop_effect 中判断计数器是否为某个步长的整数倍,从而实现分批处理或周期性检查。典型场景包括:对一组国家/省份每隔固定数量执行特殊操作,或在随机事件中用余数分流不同结果。
# 每当循环计数器 i 是 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 }
}
# 每第 3 次循环才执行的效果
log = "[GetDateText]: every 3rd iteration"
}
}
[check_variable](/wiki/trigger/check_variable):modulo_temp_variable 对临时变量取余后,几乎总是紧跟 check_variable 来判断余数是否等于某个目标值,二者是标准搭档。[set_temp_variable](/wiki/effect/set_temp_variable):在取模运算前需要先用 set_temp_variable 把原始值复制到一个工作变量,避免直接修改源数据。[for_loop_effect](/wiki/effect/for_loop_effect):提供循环计数器,是触发"周期性判断"场景的外层容器,与 modulo_temp_variable 配合实现每 N 次执行一次的控制流。[divide_temp_variable](/wiki/effect/divide_temp_variable):当需要同时获得商和余数时,可与 modulo_temp_variable 并用,分别在两份临时变量上操作。modulo_temp_variable 会就地修改 var 指定的变量,新手常忘记先用 set_temp_variable 复制一份,导致后续逻辑读到的已经是余数而非原始计数器值。value 字段引用的是另一个变量且该变量可能为 0,游戏不会自动跳过,而是产生除零异常,应在调用前用 check_variable 确保除数不为零。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_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"
}
}
[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.modulo_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.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.