Hands-On Usage
remove_from_temp_array is commonly used in mod scenarios where you need to dynamically maintain a candidate list, such as progressively removing processed elements in random event loops or removing items that fail to meet criteria while iterating through an array. The following example demonstrates removing a specified value from a candidate country array in an event:
# First add candidate elements to the temp array, then remove unwanted ones
add_to_temp_array = { array = candidate_countries value = 42 }
add_to_temp_array = { array = candidate_countries value = 17 }
# Remove a specific element by value
remove_from_temp_array = {
array = candidate_countries
value = 42
}
# Or use the shorthand format to remove directly
remove_from_temp_array = { candidate_countries = 17 }
Synergy
[add_to_temp_array](/wiki/effect/add_to_temp_array): Typically used first to populate array elements, then remove_from_temp_array is called to remove elements by condition, forming an "add/remove" cycle for temporary arrays.
[for_each_scope_loop](/wiki/effect/for_each_scope_loop): Within the loop body when iterating over an array, invoke the removal operation on elements that satisfy conditions to achieve filtered iteration.
[is_in_array](/wiki/trigger/is_in_array): Check whether the target value exists in the array before removing to avoid ineffective operations on non-existent elements.
[clear_temp_array](/wiki/effect/clear_temp_array): Used in conjunction when you need to completely reset the array; compared to deleting items one by one, clear_temp_array is more efficient, and the two complement each other for cleanup needs at different granularities.
Common Pitfalls
- Confusing the semantics of
value and index: value matches and deletes by the actual element value, while index deletes by position (starting from 0). If both are specified in the same block, the game will only use one of them, resulting in deletion of unintended elements; make sure to clarify the scenario and choose only one.
- Misusing this command on regular (non-temporary) arrays:
remove_from_temp_array only operates on temp_array. If the target is a persistent array created via add_to_array, use [remove_from_array](/wiki/effect/remove_from_array) instead; otherwise the command silently fails and the array contents remain unchanged.