Wiki

trigger · remove_from_temp_array

Definition

  • Supported scope:any
  • Supported target:none

Description

Removes an element from a temporary array using value or index
Example: remove_from_temp_array = {
	array = array_name
	value = 42 #optional, use index or this. if neither it removes last element
	index = 3 #optional, use value or this. if neither it removes last element
}
#shorter usage: remove_from_temp_array = { array_name = 42 }

Hands-On Notes

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.

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

  1. 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.
  2. 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.