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 }

实战 · 配合 · 坑

实战内容由 AI 生成,并已对照 vanilla 命令词表校验 —— 请当作起点而非权威依据。上方的定义节才是游戏自带文档原文。

实战用法

resize_temp_array 常用于动态数组管理场景,例如在循环筛选国家或省份后,需要将结果集裁剪到固定数量,或预先扩展数组为后续批量赋值腾出空间。典型场景如构建"随机选取 N 个候选目标"的逻辑:先填充数组,再用此命令截断至所需长度。

# 将临时数组 candidate_array 截断为前 3 个元素
resize_temp_array = {
    array = candidate_array
    size = 3
}

# 简写形式:直接将 candidate_array 调整为 5 个元素(新增元素默认为 0)
resize_temp_array = { candidate_array = 5 }

配合关系

  • [add_to_temp_array](/wiki/effect/add_to_temp_array):通常先用此命令向临时数组批量压入元素,再用 resize_temp_array 将数组裁剪或扩展到目标长度,二者构成"填充→调整"的标准流程。
  • [for_each_scope_loop](/wiki/effect/for_each_scope_loop):在循环体内往数组追加元素后,往往需要用 resize_temp_array 控制最终数组大小,避免数组无限增长。
  • [random_scope_in_array](/wiki/effect/random_scope_in_array):从数组中随机取作用域前,先用 resize_temp_array 确保数组大小符合预期,可防止因越界或冗余元素导致逻辑混乱。
  • [clear_temp_array](/wiki/effect/clear_temp_array):当需要重置数组并重新填充时,clear_temp_arrayresize_temp_array 组合使用,前者清空,后者重新定形。

常见坑

  1. 误用 value 字段的时机value 只在数组扩大时对新增元素生效,若新 size 小于原数组长度,末尾元素会被直接删除,value 不起任何作用——新手常误以为 value 会对现有元素进行批量重置。
  2. 混淆临时数组与持久数组resize_temp_array 只能操作 temp array(临时数组),若错误地填入普通变量数组名,脚本不会报错但效果不会生效,应改用 [resize_array](/wiki/effect/resize_array) 处理持久数组。

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.