Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Checks if any data structures under any id_string exist on calling instance
- *
- * @function ds_exists_any(_id_string)
- * @param {string} id_string id string of data structure
- * @return ds_type or false
- * @see variable_instance_get, ds_exists
- */
- function ds_exists_any(_id_string) {
- // Get ds variable from instance calling this function
- var ds = variable_instance_get(self, _id_string);
- // Exit early if variable doesn't exist on calling instance
- if (ds == undefined) {
- return false;
- }
- // Initiate ds types array for looping
- var ds_types = [ds_type_map, ds_type_list, ds_type_stack, ds_type_grid, ds_type_queue, ds_type_priority];
- for (var i = 0; i < array_length(ds_types); i++) {
- // Return type if ds of type exists
- if (ds_exists(ds, ds_types[i])) {
- return ds_types[i];
- }
- }
- return false;
- }
- /**
- * Destroys all data structures by name on calling instance
- *
- * @function ds_destroy_all([names])
- * @param {string} [names] Names of data structures to destroy
- * @return {undefined}
- * @see ds_exists_any, variable_instance_get, ds_grid_destroy
- */
- function ds_destroy_all() {
- // For each name given
- for (var i = 0; i < argument_count; i++) {
- // Get ds name
- var name = argument[i];
- // Get ds type
- var ds_type = ds_exists_any(name);
- // Exit early if it doesn't exist
- if (not ds_type) {
- continue;
- }
- // Get ds index in memory
- var ds_index = variable_instance_get(self, name);
- // Destroy ds based on type
- switch (ds_type) {
- case ds_type_grid:
- ds_grid_destroy(ds_index);
- break;
- case ds_type_list:
- ds_list_destroy(ds_index);
- break;
- case ds_type_map:
- ds_map_destroy(ds_index);
- break;
- case ds_type_priority:
- ds_priority_destroy(ds_index);
- break;
- case ds_type_queue:
- ds_queue_destroy(ds_index);
- break;
- case ds_type_stack:
- ds_stack_destroy(ds_index);
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement