Wiki

effect · find_lowest_in_array

Definition

  • Supported scope:any
  • Supported target:any

Description

Runs a loop on for each element of an array, finds the lowest value and stores result in temp variables
Example: find_lowest_in_array = {
	array = array_name
	value = value_name #optional (default 'v') lowest value in array will be stored in this temp variable
	index = index_name #optional (default 'i') index of lowest value in array will be stored in this temp variable
}

实战 · 配合 · 坑

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

实战用法

find_lowest_in_array 常用于需要从一组数值中找出最小者的场景,例如在多国竞争系统中找出工业产值最低的国家索引,或在资源分配 mod 中定位存量最少的那一格。下面是一个简单示例,从 resource_pool 数组中找出最低值并记录其索引:

find_lowest_in_array = {
    array = resource_pool
    value = min_val   # 最低数值存入 temp 变量 min_val
    index = min_idx   # 对应索引存入 temp 变量 min_idx
}
# 之后即可用 min_val / min_idx 做后续判断或操作

配合关系

  • [add_to_array](/wiki/effect/add_to_array) / [add_to_temp_array](/wiki/effect/add_to_temp_array):在调用本命令之前先向数组填充数据,是构造待查数组最常见的前置步骤。
  • [find_highest_in_array](/wiki/effect/find_highest_in_array):通常成对使用,先取最低再取最高,从而得到值域范围,用于归一化或比较极差。
  • [check_variable](/wiki/trigger/check_variable):在找到最低值后,用此触发器对 min_val 做条件判断,决定后续分支逻辑。
  • [set_temp_variable](/wiki/effect/set_temp_variable):可在循环外手动初始化辅助变量,配合本命令的结果做进一步算术(如求均值与最低值的差)。

常见坑

  1. 忽略默认变量名冲突valueindex 字段不填时默认使用 vi,而这两个名字在嵌套的 for_each_loop / while_loop_effect 内同样是默认迭代变量名,混用会导致外层循环的 v/i 被本命令覆盖,产生难以排查的逻辑错误——建议始终显式指定有语义的变量名。
  2. 对空数组调用:若数组在执行时元素数量为 0,本命令的行为未定义,结果变量可能保留上一次运行的脏值,事先用 [collection_size](/wiki/trigger/collection_size)[check_variable](/wiki/trigger/check_variable) 确认数组非空是良好习惯。

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

find_lowest_in_array is commonly used in scenarios requiring identification of the minimum value from a set of numbers—for example, locating the country index with the lowest industrial output in a multi-nation competition system, or pinpointing the cell with the least stock in a resource allocation mod. Below is a simple example that finds the lowest value in a resource_pool array and records its index:

find_lowest_in_array = {
    array = resource_pool
    value = min_val   # Lowest value stored in temp variable min_val
    index = min_idx   # Corresponding index stored in temp variable min_idx
}
# Afterwards, min_val / min_idx can be used for subsequent checks or operations

Synergy

  • [add_to_array](/wiki/effect/add_to_array) / [add_to_temp_array](/wiki/effect/add_to_temp_array): Populate the array with data before invoking this command; this is the most common prerequisite step for constructing the target array.
  • [find_highest_in_array](/wiki/effect/find_highest_in_array): Typically used in pairs—find the lowest value first, then the highest, thereby obtaining the value range for normalization or comparative analysis.
  • [check_variable](/wiki/trigger/check_variable): After finding the lowest value, use this trigger to apply conditional logic to min_val, determining subsequent branching logic.
  • [set_temp_variable](/wiki/effect/set_temp_variable): Manually initialize helper variables outside loops and combine them with this command's results for further arithmetic operations (such as computing the difference between mean and minimum).

Common Pitfalls

  1. Overlooking default variable name conflicts: When value and index fields are left unspecified, they default to v and i respectively, which are also the default iteration variable names in nested for_each_loop / while_loop_effect blocks. Mixing these will cause the outer loop's v/i to be overwritten by this command, resulting in hard-to-trace logic errors—it is strongly recommended to always explicitly specify semantically meaningful variable names.
  2. Invoking on empty arrays: If the array contains zero elements at execution time, the command's behavior is undefined and result variables may retain stale values from the previous run. It is good practice to first confirm the array is non-empty using [collection_size](/wiki/trigger/collection_size) or [check_variable](/wiki/trigger/check_variable).