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
}
modulo_temp_variableanynonemodulos a temp variable with another. Example:
modulo_temp_variable = {
var = variable_to_modulo
value = divisior
}
实战内容由 AI 生成,并已对照 vanilla 命令词表校验 —— 请当作起点而非权威依据。上方的定义节才是游戏自带文档原文。
modulo_temp_variable 常用于循环计数、周期性判断或将数值限定在某个范围内的场景,例如每隔 N 天触发一次事件、或将随机值映射到固定区间。在生成程序化内容(如地图格子编号分组、轮询国家列表索引)时也非常实用。
# 示例:判断当前循环计数是否是3的倍数
set_temp_variable = { var = remainder value = counter }
modulo_temp_variable = { var = remainder value = 3 }
if = {
limit = { check_variable = { var = remainder value = 0 } }
# 每3次执行一次的逻辑
add_to_variable = { var = milestone_count value = 1 }
}
[set_temp_variable](/wiki/effect/set_temp_variable) — 在取模运算前先将目标变量赋值或拷贝,避免直接修改原始变量。[add_to_temp_variable](/wiki/effect/add_to_temp_variable) — 与计数器配合,每次循环累加后再取模,实现周期性触发逻辑。[check_variable](/wiki/trigger/check_variable) — 取模结果通常立即用此 trigger 判断余数是否为 0(或某一预期值),决定后续分支。[for_loop_effect](/wiki/effect/for_loop_effect) — 循环体内常配合取模来做分组处理,例如将循环索引按组数取模以分配不同行为。modulo_temp_variable 会就地修改 var 指定的变量,如果直接写入业务用的计数器变量,该变量的原始值就被余数覆盖了。应先用 set_temp_variable 把值拷贝到一个临时中间变量,再对中间变量做取模。value 字段若在运行时解析为 0,会引发除零错误使效果静默失败甚至报错。在 value 来自动态变量时,务必先用 [check_variable](/wiki/trigger/check_variable) 或 [clamp_temp_variable](/wiki/effect/clamp_temp_variable) 保证其大于 0。