ds_exists

This function checks if a data structure of the given type with the given index exists.

You supply the DS reference (as held in a variable) and the DS type, which can be any of the constants listed below, and the function will return true if the data structure exists and false otherwise.

DS Type Constant
ConstantDescription
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

NOTE You cannot use this function to check the type of a data structure, as the same index number may be used by multiple data structures of differing types.

 

Syntax:

ds_exists(ind, type)

ArgumentTypeDescription
indAny DS ReferenceThe variable index to check for the data structure
typeDS Type ConstantThe type of data structure to check for (see the list of constants above)

 

Returns:

Boolean

 

Example:

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

The above code checks the (previously initialised) variable ai_grid to see if it indexes a DS grid type data structure. If it doesn't, it creates one and stores its handle in the variable.