Wiki

effect · 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 }

实战 · 配合 · 坑

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

实战用法

remove_from_temp_array 常用于需要动态维护候选列表的 mod 场景,例如在随机事件循环中逐步剔除已处理的元素,或在遍历数组时按条件移除不满足要求的项目。以下示例演示在事件中从候选国家数组里移除一个指定值:

# 先向临时数组中添加候选元素,再移除不需要的
add_to_temp_array = { array = candidate_countries value = 42 }
add_to_temp_array = { array = candidate_countries value = 17 }

# 按值移除特定元素
remove_from_temp_array = {
    array = candidate_countries
    value = 42
}

# 或使用短格式直接移除
remove_from_temp_array = { candidate_countries = 17 }

配合关系

  • [add_to_temp_array](/wiki/effect/add_to_temp_array):通常先用它向数组填充元素,再用 remove_from_temp_array 按条件剔除,两者构成临时数组的"增删"闭环。
  • [for_each_scope_loop](/wiki/effect/for_each_scope_loop):在遍历数组的循环体内,对满足条件的元素调用移除操作,实现过滤式迭代。
  • [is_in_array](/wiki/trigger/is_in_array):在移除前先检测目标值是否存在于数组,避免对不存在的元素做无效操作。
  • [clear_temp_array](/wiki/effect/clear_temp_array):当需要彻底重置数组时与之配合使用;相比逐条删除,clear_temp_array 更高效,两者在不同粒度的清理需求下互补。

常见坑

  1. 混淆 valueindex 的语义value 是按元素的实际值匹配删除,index 是按位置(从 0 开始)删除,若两者同时写入同一块,游戏只会使用其中一个,导致删除了预期之外的元素;需明确场景后只选其一。
  2. 对普通(非临时)数组误用此命令remove_from_temp_array 只作用于 temp_array,若目标是通过 add_to_array 创建的持久数组,应改用 [remove_from_array](/wiki/effect/remove_from_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

remove_from_temp_array is commonly used in mod scenarios where you need to dynamically maintain a candidate list, such as progressively removing processed elements in random event loops or removing items that fail to meet criteria while iterating through an array. The following example demonstrates removing a specified value from a candidate country array in an event:

# First add candidate elements to the temp array, then remove unwanted ones
add_to_temp_array = { array = candidate_countries value = 42 }
add_to_temp_array = { array = candidate_countries value = 17 }

# Remove a specific element by value
remove_from_temp_array = {
    array = candidate_countries
    value = 42
}

# Or use the shorthand format to remove directly
remove_from_temp_array = { candidate_countries = 17 }

Synergy

  • [add_to_temp_array](/wiki/effect/add_to_temp_array): Typically used first to populate array elements, then remove_from_temp_array is called to remove elements by condition, forming an "add/remove" cycle for temporary arrays.
  • [for_each_scope_loop](/wiki/effect/for_each_scope_loop): Within the loop body when iterating over an array, invoke the removal operation on elements that satisfy conditions to achieve filtered iteration.
  • [is_in_array](/wiki/trigger/is_in_array): Check whether the target value exists in the array before removing to avoid ineffective operations on non-existent elements.
  • [clear_temp_array](/wiki/effect/clear_temp_array): Used in conjunction when you need to completely reset the array; compared to deleting items one by one, clear_temp_array is more efficient, and the two complement each other for cleanup needs at different granularities.

Common Pitfalls

  1. Confusing the semantics of value and index: value matches and deletes by the actual element value, while index deletes by position (starting from 0). If both are specified in the same block, the game will only use one of them, resulting in deletion of unintended elements; make sure to clarify the scenario and choose only one.
  2. Misusing this command on regular (non-temporary) arrays: remove_from_temp_array only operates on temp_array. If the target is a persistent array created via add_to_array, use [remove_from_array](/wiki/effect/remove_from_array) instead; otherwise the command silently fails and the array contents remain unchanged.