Wiki

trigger · is_in_array

Definition

  • Supported scope:any
  • Supported target:none

Description

Checks if an element is in array
Example: is_in_array = {
	array = array_name
	value = 42
}
#shorter usage: is_in_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

is_in_array is commonly found in mod scenarios that require tracking "processed countries/states" or "selected option lists". For example, checking whether a country TAG or value has already been added to a custom queue array, thereby preventing duplicate event or effect triggers.

# Check if the current country's TAG variable is already in the "visited countries" array
if = {
    limit = {
        is_in_array = {
            array = visited_countries_array
            value = THIS
        }
    }
    # Already in array, skip processing
    custom_effect_tooltip = already_visited_tt
}

Synergy

  • [add_to_array](/wiki/effect/add_to_array) — First add elements to the array, then use is_in_array to verify successful insertion, or prevent duplicate additions in subsequent triggers.
  • [remove_from_array](/wiki/effect/remove_from_array) — Pair with is_in_array to form a safe "check-then-remove" pattern, avoiding logic errors from removing non-existent elements.
  • [collection_size](/wiki/trigger/collection_size) — Commonly used in the same array logic block: first confirm the array is non-empty and contains the target element, then perform further size comparisons.
  • [check_variable](/wiki/trigger/check_variable) — Frequently combined: check_variable validates numeric conditions, is_in_array validates membership, and both together form composite guard conditions.

Common Pitfalls

  1. Array name spelling and scope mismatch: Arrays exist at global, country, and local scopes. Referencing an array name in the wrong scope (e.g., using an array name assigned only in global scope within a country scope) causes is_in_array to always return false silently, making debugging extremely difficult.
  2. Type mismatch when comparing object references instead of values: When the array stores scope references (such as TAGs), directly writing a string tag name is not equivalent to the scope object itself. Ensure that the type used when inserting into the array matches the type used when checking (variable values vs. scope tokens), otherwise matching will always fail.