effect · clear_temp_array
Definition
- Supported scope:
any - Supported target:
none
Description
Clears the contents of a temporary array
Example: clear_temp_array = array_name
clear_temp_arrayanynoneClears the contents of a temporary array
Example: clear_temp_array = array_name
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.
clear_temp_array is commonly used in scenarios where you need to reuse a temporary array with the same name within a single event or effect block. For example, you might use an array to collect a batch of countries or states, process them, then clear and refill the array to avoid pollution from residual data in the previous iteration. In looping scripts (such as counting countries that meet certain conditions), clearing the array before entering each new conditional branch ensures clean data.
# Collect all states meeting the condition first, then clear after processing to allow array reuse
every_state = {
limit = { is_controlled_by = ROOT }
add_to_temp_array = { array = controlled_states val = THIS }
}
find_highest_in_array = { array = controlled_states out = best_state }
# Processing complete, clear to allow subsequent logic to reuse the same-named array
clear_temp_array = controlled_states
[add_to_temp_array](/wiki/effect/add_to_temp_array): The most direct companion—immediately repopulate the array after clearing it, forming the standard "reset→rebuild" workflow.[for_each_scope_loop](/wiki/effect/for_each_scope_loop): After iterating through the array and executing logic, call clear_temp_array to release the array and prevent data accumulation when the event is triggered multiple times.[resize_temp_array](/wiki/effect/resize_temp_array): Sometimes after clearing you need to preallocate slots of a fixed size; the two are often used together to complete full array initialization.[collection_size](/wiki/trigger/collection_size): Before clearing, you can use this trigger to check if the array is non-empty, avoiding redundant operations on empty arrays and making your logic more rigorous.clear_array instead of clear_temp_array: clear_array clears persistent variable arrays (saved in the save file), while clear_temp_array only affects temporary arrays in the current execution frame. The two cannot be used interchangeably; using the wrong one will either unexpectedly erase save data or cause script errors.