此函数检查是否存在具有给定索引的给定类型的数据结构。
您提供 DS 引用 (保存在变量中) 和 DS 类型 (可以是下面列出的任何常量),如果数据结构存在,函数将返回 true,否则返回 false。
DS 类型常量 | |
---|---|
常量 | 描述 |
ds_type_map | A map data structure |
ds_type_list | A list data structure |
ds_type_stack | A stack data structure |
ds_type_grid | A grid data structure |
ds_type_queue | A queue data structure |
ds_type_priority | A priority data structure |
注意 您不能使用此函数来检查数据结构的类型,因为相同的索引号可能被不同类型的多个数据结构使用。
ds_exists(ind, type)
参数 | 类型 | 描述 |
---|---|---|
ind | Any DS Reference | 用于检查数据结构的变量索引 |
type | DS 类型常量 | 要检查的数据结构类型(参见上面的常量列表) |
if (!ds_exists(ai_grid, ds_type_grid))
{
ai_grid = ds_grid_create(room_width / 32, room_height / 32);
}
上面的代码检查 (之前初始化的) 变量 ai_grid 以查看它是否为 DS 网格类型数据结构建立索引。如果没有,它会创建一个并将其句柄存储在变量中。