trigger · 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 the same temporary array name across loops or multi-stage calculations—for example, collecting a list of countries that meet certain conditions, processing them, clearing the array, and then performing another collection pass. Typical applications include dynamic event option generation, filtering state/province lists by criteria, and other complex array operations that require a "reset" step in the workflow.
# In an effect block, use the array first, then clear it to allow subsequent logic to reuse it
effect = {
# ... processing logic for target_countries array ...
clear_temp_array = target_countries # Clear to prevent previous iteration data from polluting the next result
# Re-populate target_countries with fresh data
for_each_scope_loop = {
array = faction_members
add_to_temp_array = { array = target_countries val = THIS }
}
}
[add_to_temp_array](/wiki/effect/add_to_temp_array): The most direct partner—use add_to_temp_array to write elements into the array, and after processing, use clear_temp_array to remove them, providing a clean slate for the next write operation.[for_each_scope_loop](/wiki/effect/for_each_scope_loop): If the array needs to be reconstructed before loop execution, commonly invoke clear_temp_array outside the loop beforehand to ensure the array is empty and prevent duplicate accumulation.[remove_from_temp_array](/wiki/effect/remove_from_temp_array): Use remove_from_temp_array when you only need to remove certain elements, but switch to clear_temp_array when you need a complete reset. These two form a complementary relationship of "partial cleanup vs. full cleanup".[is_in_array](/wiki/trigger/is_in_array): Before clearing the array, you typically perform one last query check with is_in_array. Together they constitute the standard pattern of "use and then clear".clear_temp_array can only clear arrays that begin with temp_ (or temporary arrays declared within the same effect block). If you want to clear ordinary arrays persisted via set_variable and similar methods, use [clear_array](/wiki/effect/clear_array) instead. Mixing these up causes script errors or silent logic failures.clear_temp_array inside for_each_scope_loop or while_loop_effect will wipe the array on every iteration, which usually results in data loss. The clear operation should be placed outside the loop (before it starts or after it ends). Otherwise, data accumulated within the loop will be repeatedly erased, causing hard-to-trace logic bugs.