Wiki

effect · round_temp_variable

Definition

  • Supported scope:any
  • Supported target:none

Description

Rounds a temporary variable
Example: round_temp_variable = num_dogs

实战 · 配合 · 坑

实战内容由 AI 生成,并已对照 vanilla 命令词表校验 —— 请当作起点而非权威依据。上方的定义节才是游戏自带文档原文。

实战用法

round_temp_variable 常用于经济、人口或战斗计算场景中,当你通过乘除法得到一个带小数的临时变量后,需要将其取整以便后续赋值或显示时使用。例如计算某国工业产出的平均值、按比例分配资源点数时,往往需要先计算再取整,避免浮点数污染后续逻辑。

# 计算平均工厂数并取整
set_temp_variable = { avg_factories = total_factories }
divide_temp_variable = { avg_factories = num_states }
round_temp_variable = avg_factories
add_to_variable = { final_output = avg_factories }

配合关系

  • [divide_temp_variable](/wiki/effect/divide_temp_variable):除法运算几乎必然产生小数,取整前的最直接前置步骤,两者几乎形影不离。
  • [multiply_temp_variable](/wiki/effect/multiply_temp_variable):乘法与百分比换算同样会引入小数,计算完成后用 round_temp_variable 收尾以保证整数结果。
  • [set_temp_variable](/wiki/effect/set_temp_variable):先用它初始化或赋值临时变量,再经过运算,最终交由 round_temp_variable 取整,构成完整的变量处理流程。
  • [check_variable](/wiki/trigger/check_variable):取整后通常需要在 trigger 中对结果进行比较判断,check_variable 是读取临时变量值的标准手段。

常见坑

  1. 误用于永久变量round_temp_variable 只能作用于 temp_variable(临时变量),若想对普通变量取整应使用 [round_variable](/wiki/effect/round_variable),混用会导致脚本报错或静默失效。
  2. 取整时机错误:在连续运算链中过早取整会丢失精度,例如先取整再做乘法,结果与预期偏差可能很大,应当在所有算术操作完成后的最后一步再调用取整。

Hands-On Notes

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.

Hands-On Usage

round_temp_variable is commonly used in economic, population, or combat calculation scenarios. When you obtain a decimal temporary variable through multiplication or division operations, rounding it to an integer is necessary for subsequent assignment or display purposes. For example, when calculating the average number of factories for a country or allocating resource points proportionally, you typically need to perform the calculation first and then round to avoid floating-point precision issues contaminating subsequent logic.

# Calculate average factory count and round
set_temp_variable = { avg_factories = total_factories }
divide_temp_variable = { avg_factories = num_states }
round_temp_variable = avg_factories
add_to_variable = { final_output = avg_factories }

Synergy

  • [divide_temp_variable](/wiki/effect/divide_temp_variable): Division operations almost inevitably produce decimals, making it the direct predecessor step before rounding. These two are virtually inseparable.
  • [multiply_temp_variable](/wiki/effect/multiply_temp_variable): Multiplication and percentage conversions likewise introduce decimals. After calculation, use round_temp_variable to finalize and ensure integer results.
  • [set_temp_variable](/wiki/effect/set_temp_variable): Initialize or assign temporary variables with it first, then perform operations, and finally employ round_temp_variable to round the result, forming a complete variable processing workflow.
  • [check_variable](/wiki/trigger/check_variable): After rounding, you typically need to compare and evaluate results in triggers. check_variable is the standard method for reading temporary variable values.

Common Pitfalls

  1. Misuse on permanent variables: round_temp_variable only works on temp_variable (temporary variables). If you need to round regular variables, use [round_variable](/wiki/effect/round_variable) instead. Mixing them will cause script errors or silent failures.
  2. Incorrect rounding timing: Rounding too early in a chain of continuous operations causes precision loss. For example, rounding before multiplication can result in significant deviation from expected values. Always perform rounding as the final step after all arithmetic operations are complete.