命令百科

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. 取整时机错误:在连续运算链中过早取整会丢失精度,例如先取整再做乘法,结果与预期偏差可能很大,应当在所有算术操作完成后的最后一步再调用取整。