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),错误混用不会有语法报错但数据不会被修改。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.
round_temp_variable is commonly used in mod scenarios involving complex numerical calculations, such as computing population ratios, resource allocation, or percentages. It rounds floating-point results to integers to prevent decimal precision errors in subsequent comparisons or displays. A typical use case is tidying up temporary variables at the end of a numerical derivation chain in dynamic events or decisions, ensuring that subsequent check_variable logic remains clean and reliable.
# Calculate half the factory count of a state and round the result for subsequent checks
set_temp_variable = { temp_half_factories = num_factories }
divide_temp_variable = { temp_half_factories = 2 }
round_temp_variable = temp_half_factories
# After this, temp_half_factories is an integer and can be safely compared
[divide_temp_variable](/wiki/effect/divide_temp_variable): Division operations almost inevitably produce decimals; rounding the result with round_temp_variable immediately afterward is the most common pairing.[multiply_temp_variable](/wiki/effect/multiply_temp_variable): Multiplying by coefficients (such as percentage weights) can also yield non-integer results; rounding before passing to downstream logic is more robust.[check_variable](/wiki/trigger/check_variable): Rounded temporary variables are used in conditional comparisons, avoiding unexpected judgment outcomes due to floating-point precision variance.[modulo_temp_variable](/wiki/effect/modulo_temp_variable): When modulo operations require operands to have integer semantics, round_temp_variable should be applied before the modulo operation; otherwise, results may not be as expected.round_temp_variable is used within trigger blocks and belongs to the conditional evaluation context; it cannot be placed in pure effect blocks (such as on_action, complete_effect, etc.)—those should use the same-named effect version (the whitelist also contains round_temp_variable as an effect). Confusing contexts will cause script errors or silent behavioral failures.round_temp_variable only operates on temp_variable (temporary variables). To round ordinary persistent variables, use [round_variable](/wiki/effect/round_variable) instead. Mixing them incorrectly will not produce a syntax error, but the data will not be modified.