trigger · round_temp_variable
Definition
- Supported scope:
any - Supported target:
none
Description
Rounds a temporary variable
Example: round_temp_variable = num_dogs
round_temp_variableanynoneRounds a temporary variable
Example: round_temp_variable = num_dogs
实战内容由 AI 生成,并已对照 vanilla 命令词表校验 —— 请当作起点而非权威依据。上方的定义节才是游戏自带文档原文。
round_temp_variable 常用于涉及复杂数值计算的 mod 场景,例如计算人口比例、资源分配或百分比后,将浮点结果取整以避免后续比较或显示出现小数误差。典型场景是在动态事件或决策的数值推导链末尾对临时变量进行整理,确保后续 check_variable 逻辑干净可靠。
# 计算某省份工厂数量的一半并取整,用于后续判断
set_temp_variable = { temp_half_factories = num_factories }
divide_temp_variable = { temp_half_factories = 2 }
round_temp_variable = temp_half_factories
# 此后 temp_half_factories 已为整数,可安全比较
[divide_temp_variable](/wiki/effect/divide_temp_variable):除法运算几乎必然产生小数,round_temp_variable 紧随其后对结果取整是最常见的组合。[multiply_temp_variable](/wiki/effect/multiply_temp_variable):乘以系数(如百分比权重)后同样可能得到非整数,取整后再传入后续逻辑更稳健。[check_variable](/wiki/trigger/check_variable):取整后的临时变量用于条件比较,避免因浮点精度差异导致判断结果不符合预期。[modulo_temp_variable](/wiki/effect/modulo_temp_variable):取模运算要求操作数为整数语义时,应先 round_temp_variable 再做取模,否则结果可能不符合预期。round_temp_variable 在 trigger 块中使用,属于条件判断上下文,不能放在纯 effect 块(如 on_action、complete_effect 等)中——那里应使用同名的 effect 版本(白名单中同样存在 round_temp_variable 作为 effect),混淆上下文会导致脚本报错或行为静默失效。round_temp_variable 只作用于 temp_variable(临时变量),若想对普通持久变量取整,需要使用 [round_variable](/wiki/effect/round_variable),错误混用不会有语法报错但数据不会被修改。