Wiki

effect · resize_temp_array

Definition

  • Supported scope:any
  • Supported target:none

Description

Resizes a temp array
Example: resize_temp_array = {
	array = array_name
	value = 42 #optional, if not specified and array grows the new elements are set to this (default 0)
	size = 3 #if higher than old size, new elements are added to end. otherwise last elements are removed to match to new size
}
#shorter usage: resize_temp_array = { array_name = 3 }

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

resize_temp_array is commonly used in dynamic array management scenarios, such as when filtering countries or provinces in a loop and needing to trim the result set to a fixed size, or pre-expanding an array to make room for subsequent batch assignments. A typical use case is building logic for "randomly select N candidate targets"—first populate the array, then use this command to truncate it to the desired length.

# Truncate the temporary array candidate_array to the first 3 elements
resize_temp_array = {
    array = candidate_array
    size = 3
}

# Shorthand form: directly resize candidate_array to 5 elements (new elements default to 0)
resize_temp_array = { candidate_array = 5 }

Synergy

  • [add_to_temp_array](/wiki/effect/add_to_temp_array): Typically used first to bulk add elements to a temporary array, then resize_temp_array trims or expands the array to the target size, forming a standard "populate → adjust" workflow.
  • [for_each_scope_loop](/wiki/effect/for_each_scope_loop): After appending elements to an array within a loop body, resize_temp_array is often needed to control the final array size and prevent unbounded growth.
  • [random_scope_in_array](/wiki/effect/random_scope_in_array): Before randomly selecting a scope from an array, use resize_temp_array first to ensure the array size meets expectations, preventing logic confusion caused by out-of-bounds access or redundant elements.
  • [clear_temp_array](/wiki/effect/clear_temp_array): When resetting an array and refilling it, clear_temp_array and resize_temp_array are used together—the former clears, the latter reshapes.

Common Pitfalls

  1. Misusing the value field timing: value only applies to new elements when the array expands. If the new size is smaller than the original array length, trailing elements are simply deleted and value has no effect—beginners often mistakenly assume value will batch-reset existing elements.
  2. Confusing temporary arrays with persistent arrays: resize_temp_array only operates on temp arrays. If you mistakenly enter a regular variable array name, the script won't error but the effect won't work; use [resize_array](/wiki/effect/resize_array) instead for persistent arrays.