ds_exists

此函数检查是否存在具有给定索引的给定类型的数据结构。

您提供 DS 引用 (保存在变量中) 和 DS 类型 (可以是下面列出的任何常量),如果数据结构存在,函数将返回 true,否则返回 false

DS 类型常量
常量描述
ds_type_mapA map data structure
ds_type_listA list data structure
ds_type_stackA stack data structure
ds_type_gridA grid data structure
ds_type_queueA queue data structure
ds_type_priorityA priority data structure

注意 您不能使用此函数来检查数据结构的类型,因为相同的索引号可能被不同类型的多个数据结构使用。

 

语法:

ds_exists(ind, type)

参数类型描述
indAny DS Reference用于检查数据结构的变量索引
typeDS 类型常量要检查的数据结构类型(参见上面的常量列表)

 

返回:

Boolean

 

例子:

if (!ds_exists(ai_grid, ds_type_grid))
{
    ai_grid = ds_grid_create(room_width / 32, room_height / 32);
}

上面的代码检查 (之前初始化的) 变量 ai_grid 以查看它是否为 DS 网格类型数据结构建立索引。如果没有,它会创建一个并将其句柄存储在变量中。