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 }

实战 · 配合 · 坑

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

实战用法

remove_from_temp_array 常见于需要在循环中动态维护一个临时列表的场景,例如在随机事件中从候选国家池里剔除已处理的元素,或在连续触发逻辑中过滤掉不再满足条件的数值项。下面示例展示在一个检查流程中,用索引精确移除数组某位置的元素:

# 检查数组中索引 0 的元素后将其移除
if = {
    limit = {
        check_variable = { var:my_temp_array^0 > 10 }
    }
    remove_from_temp_array = {
        array = my_temp_array
        index = 0
    }
}

配合关系

  • [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):在移除前先用该 trigger 确认目标值确实存在于数组中,避免对空数组或不存在元素执行操作引发错误。
  • [clear_temp_array](/wiki/effect/clear_temp_array):当需要一次性清空而非逐个移除时与之形成互补,视业务需求选择「单删」还是「全清」。

常见坑

  1. 同时指定 valueindex 导致行为不可预期:两个字段只应二选一(或都不填以移除末尾元素),若同时写入引擎会优先使用某一字段,另一字段被静默忽略,新手容易误以为两个条件会叠加校验。
  2. remove_from_temp_array 当作 trigger 使用:尽管它出现在 trigger 白名单中,其实际作用是对数组状态的修改,不能用它的「返回值」来做条件判断;若写在纯 trigger 块(如 limit)内期望它返回真/假以控制流程,逻辑将不会如预期工作。

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.