effect · clear_temp_array
Definition
- Supported scope:
any - Supported target:
none
Description
Clears the contents of a temporary array
Example: clear_temp_array = array_name
clear_temp_arrayanynoneClears the contents of a temporary array
Example: clear_temp_array = array_name
实战内容由 AI 生成,并已对照 vanilla 命令词表校验 —— 请当作起点而非权威依据。上方的定义节才是游戏自带文档原文。
clear_temp_array 常用于需要在同一事件或 effect 块中复用同名临时数组的场景,例如先用数组收集一批国家或州,处理完毕后清空再重新填充,避免上一轮残留数据污染结果。在循环类脚本(如统计满足条件的国家数量)中,每次进入新的判断分支前清空数组可确保数据干净。
# 先收集所有符合条件的州,处理后清空以便复用
every_state = {
limit = { is_controlled_by = ROOT }
add_to_temp_array = { array = controlled_states val = THIS }
}
find_highest_in_array = { array = controlled_states out = best_state }
# 处理完毕,清空以便后续逻辑复用同名数组
clear_temp_array = controlled_states
[add_to_temp_array](/wiki/effect/add_to_temp_array):最直接的搭档,清空数组后立刻重新向其填充元素,构成「重置→重建」的标准流程。[for_each_scope_loop](/wiki/effect/for_each_scope_loop):遍历数组并执行逻辑后调用 clear_temp_array 释放数组,防止多次触发事件时数据累积。[resize_temp_array](/wiki/effect/resize_temp_array):有时在清空后需要预分配固定大小的槽位,两者常配合完成数组的完整初始化。[collection_size](/wiki/trigger/collection_size):在清空前可用此触发器检查数组是否非空,避免对空数组做多余操作,逻辑更严谨。clear_array 而非 clear_temp_array:clear_array 清除的是持久变量数组(保存在存档中),而 clear_temp_array 只作用于当前执行帧的临时数组,两者不可混用;用错会导致意外清除存档数据或脚本报错。