Hands-On Usage
find_highest_in_array is commonly used in scenarios where you need to extract the maximum value from a set of dynamic numbers—such as comparing a specific resource across multiple countries, finding the highest score from a batch of temporary calculation results, or identifying the top-scoring candidate in a custom technology or event system. The following example demonstrates finding the maximum value from an array storing province resistance values and recording its index:
find_highest_in_array = {
array = province_resistance_values
value = highest_resistance # Store the highest value in highest_resistance
index = highest_index # Store the corresponding index in highest_index
}
check_variable = {
var = highest_resistance
value = 50
compare = greater_than
}
Synergy
[add_to_array](/wiki/effect/add_to_array) / [add_to_temp_array](/wiki/effect/add_to_temp_array): Before executing find_highest_in_array, you must first populate the array with values using these commands; searching an empty array is meaningless.
[check_variable](/wiki/trigger/check_variable): After finding the highest value, it is standard practice to immediately use check_variable to perform a threshold check on the temporary variable storing the result—this is the most common subsequent condition validation approach.
[is_in_array](/wiki/trigger/is_in_array): After confirming the index or element corresponding to the highest value, you can pair it with is_in_array to verify whether that element belongs to a specific set, enabling more granular filtering logic.
[find_lowest_in_array](/wiki/effect/find_lowest_in_array): Often paired with find_highest_in_array to retrieve both maximum and minimum values simultaneously, useful for calculating range or performing dual-end comparisons.
Common Pitfalls
- Overlooking default variable name conflicts: If the
value and index fields are not explicitly specified, they default to writing into temporary variables v and i respectively. These names are extremely generic, and if an outer loop (such as for_each_loop) is already using v/i, the call will silently overwrite the original values, corrupting the outer loop's logic. Always manually specify unique variable names.
- Undefined behavior when calling on empty arrays: If the target array is uninitialized or has zero length when called,
find_highest_in_array will not throw an error, but the resulting variable's value is unpredictable (it may retain a previous value or be zero). Performing a direct check_variable check on it will produce incorrect logic. Always confirm the array is non-empty using [collection_size](/wiki/trigger/collection_size) before calling.