You are not logged in.
Pages: 1
GM:Studio lets us nest data structures in each other, but got hard time finding them inside ds_lists, which sometimes is needed while working with JSON.
/// ds_list_find_ds(list id, ds id)
//
// Finds nested data structure inside ds_list
// Usefull when working with JSON
//
// Sometimes you want to hold one data structure in another.
// In this example in ds_list. it works fine, you just save its id.
// Problem is when you got id of nested structure and want to find it inside list
// ds_list_find_index() returns -1, but we can compare every value in list to id
//
// list id id of ds_list, real
// ds id id of any data structure saved inside ds_list, real
//
// Returns position or -1
//
/// GMLscripts.com/license
var m=argument0;
var r=-1;
for (var i=0; i<ds_list_size(m); i++) {
if(m[|i]==argument1) {
r=i;
break;
}
}
return r;
/// ds_list_delete_ds(list id, ds id)
//
// Finds and deletes nested data structure inside ds_list
// Usefull when working with JSON
//
// Sometimes you want to hold one data structure in another.
// In this example in ds_list. it works fine, you just save its id.
// Problem is when you got id of nested structure and want to find it inside list
// ds_list_find_index() returns -1, but we can compare every value in list to id
//
// list id id of ds_list, real
// ds id id of any data structure saved inside ds_list, real
//
// Returns true on success
//
/// GMLscripts.com/license
var m=argument0;
var r=false;
for (var i=0; i<ds_list_size(m); i++) {
if(m[|i]==argument1) {
ds_list_delete(m, i);
r=true;
}
}
return r;
ds_list_delete_ds() can be changed to delete only one position if structure is found more than one time by adding break.
Pages: 1