Hands-On Usage
remove_from_temp_array is commonly used in scenarios requiring dynamic maintenance of a temporary list during loops—for example, removing processed elements from a candidate country pool in random events, or filtering out values that no longer meet conditions in continuous trigger logic. The example below demonstrates precisely removing an element at a specific array position by index during a validation process:
# Check the element at index 0 in the array and then remove it
if = {
limit = {
check_variable = { var:my_temp_array^0 > 10 }
}
remove_from_temp_array = {
array = my_temp_array
index = 0
}
}
Synergy
[add_to_temp_array](/wiki/effect/add_to_temp_array): Write elements to the temporary array first, then use remove_from_temp_array to remove specific items by value or index, forming a complete "enqueue → dequeue" management workflow.
[for_each_scope_loop](/wiki/effect/for_each_scope_loop): After iterating through array contents, invoke this command on elements meeting the condition to remove them, enabling filtered iteration.
[is_in_array](/wiki/trigger/is_in_array): Confirm the target value actually exists in the array using this trigger before removal, preventing errors from operations on empty arrays or non-existent elements.
[clear_temp_array](/wiki/effect/clear_temp_array): When you need to clear everything at once rather than remove items one by one, this serves as a complementary tool—choose between "single deletion" and "full clear" based on your requirements.
Common Pitfalls
- Specifying both
value and index causes unexpected behavior: These two fields should be mutually exclusive (or both omitted to remove the last element). If both are provided, the engine will prioritize one field while silently ignoring the other, leading beginners to mistakenly believe both conditions stack together.
- Using
remove_from_temp_array as a trigger: Although it appears in trigger whitelists, its actual function is modifying array state, not returning a boolean value for conditional logic. If written inside a pure trigger block (such as limit) expecting it to return true/false to control flow, the logic will not behave as intended.