Hands-On Usage
add_to_temp_array is most commonly used in trigger blocks for temporary data collection before condition checks via collection_size or is_in_array. A typical pattern involves collecting countries or values meeting certain criteria into a temporary array within an if conditional block, then performing statistical or query operations on that array in subsequent triggers. Since temporary arrays persist only for the current effect/trigger execution cycle, they are ideal for one-time intermediate result storage.
# Example: Add current variable value to temporary array in trigger, then check if array contains target value
if = {
limit = {
add_to_temp_array = { array = my_temp result = 1 }
is_in_array = { array = my_temp value = 1 }
}
# Logic after condition is met
}
Synergy
[is_in_array](/wiki/trigger/is_in_array): Immediately after adding elements to a temporary array, use is_in_array to check if a value exists within it—this is the classic "write-then-query" pattern.
[collection_size](/wiki/trigger/collection_size): After progressively pushing multiple values into a temporary array, use collection_size to count the quantity for threshold checks, commonly used in "item count reaching N" logic.
[clear_temp_array](/wiki/trigger/clear_temp_array): When reusing the same-named temporary array within a single trigger block, clear it first before writing to prevent stale data from interfering with judgment results.
[find_highest_in_array](/wiki/trigger/find_highest_in_array): After populating a temporary array, use find_highest_in_array to extract the maximum value into a temporary variable for numerical comparison, suitable for sorting and filtering scenarios.
Common Pitfalls
- Treating temporary arrays as persistent storage: Arrays written via
add_to_temp_array disappear after the current script execution ends and cannot be preserved across event options or on_action contexts. Data that must persist across frames or events should instead use add_to_array (effect-side) paired with standard variables.
- Confusing effect syntax within pure trigger contexts: Although
add_to_temp_array appears in trigger whitelists, its behavior is fundamentally a "write operation." Misusing it in read-only limit blocks may cause unexpected side effects or script errors. Always clarify the contexts where it is permitted and avoid conflating it with its effect-side counterpart.