(includes a GM8 Example, or Code below)
After some requests for more than 1 Value for every Entry of a ds_list i wrote this solution. It's like ds_list, but with arbitary Fields and faster sort.
1.2
dl_copy_structure(list, destlist);
Copy Structure of list to destlist.
- New Structure-Fieldīs will be added to all Entrys if List is already filled. (for dl_field_add.. Functions)
dl_insert(list, index);
Insert Entry after given index.
dl_swap(list, first, second);
Swap 2 Entrys by his Index.
dl_find_string_read_string(list, field, findstr);
Search in any Field of all Entrys findstr and read a String from given Field.
dl_find_string_read_real(list, field, findstr);
Search in any Field of all Entrys findstr and read a Real from given Field.
dl_find_real_read_string(list, field, findstr);
Search in any Field of all Entrys findreal and read a String from given Field.
dl_find_real_read_real(list, field, findstr);
Search in any Field of all Entrys findreal and read a Real from given Field.
Functions
dl_create_list();
Create a new List and returns the ID.
dl_free_list(list);
Delete the given List.
dl_field_add_string(list, name, str);
Add a Structure-Field to list with a default Value.
dl_field_add_real(list, name, real);
Add a Structure-Field to list with a default Value.
dl_field_delete(list, name);
Remove the given Structure-Field from list.
dl_add(list);
Add new Entry with pre-constructed Structure.
dl_insert(list, index);
Insert Entry after given index.
dl_swap(list, first, second);
Swap 2 Entrys by his Index.
dl_delete_byindex(list, index);
Delete Entry by his Index.
dl_clear(list);
Clear all Entrys from list.
dl_size(list);
Returns the number of Entrys in list.
dl_sort_bystring(list, field, sort);
Sort a List by given Structure-Field. (use dl_sort_asc or dl_sort_desc for sort)
dl_sort_byreal(list, field, sort);
Sort a List by given Structure-Field. (use dl_sort_asc or dl_sort_desc for sort)
dl_read_string(list, index, fieldname);
Read the Value from given Structure Field from given Entry.
dl_read_real(list, index, fieldname);
Read the Value from given Structure Field from given Entry.
dl_write_string(list, index, fieldname, str);
Write a Value in given Structure Field in given Entry.
dl_write_real(list, index, fieldname, real);
Write a Value in given Structure Field in given Entry.
dl_find_string_read_string(list, field, findstr);
Search in any Field of all Entrys findstr and read a String from given Field.
dl_find_string_read_real(list, field, findstr);
Search in any Field of all Entrys findstr and read a Real from given Field.
dl_find_real_read_string(list, field, findstr);
Search in any Field of all Entrys findreal and read a String from given Field.
dl_find_real_read_real(list, field, findstr);
Search in any Field of all Entrys findreal and read a Real from given Field.
Example
// DynamicStructuredList 1.0 by Alex W.
// www.mevedia.de
list = dl_create_list();
// Build Structure
// We can define a default Value.
dl_field_add_string(list, "Name", "");
dl_field_add_real(list, "Age", 0);
// Use List / add Entrys
// Structure will be now used for every List-Entry.
index = dl_add(list); // Returns Index 0
dl_write_string(list, index, "Name", "Xa");
dl_write_real(list, index, "Age", 16);
index = dl_add(list); // Returns Index 1
dl_write_string(list, index, "Name", "Aim");
dl_write_real(list, index, "Age", 16);
index = dl_add(list); // Returns Index 2
dl_write_string(list, index, "Name", "Tim");
dl_write_real(list, index, "Age", 16);
index = dl_add(list); // Returns Index 3
dl_write_string(list, index, "Name", "Sven");
dl_write_real(list, index, "Age", 28);
index = dl_add(list); // Returns Index 4
dl_write_string(list, index, "Name", "Lisa");
dl_write_real(list, index, "Age", 23);
dl_delete_byindex(list, 3);
// Sort List
// Use dl_sort_asc or dl_sort_desc.
dl_sort_bystring(list, "Name", dl_sort_asc);
// Read List
// dl_size() returns all Entrys, but Index starts from zero.
c=0;
repeat(dl_size(list))
{
show_message(dl_read_string(list, c, "Name")+" is "+string(dl_read_real(list, c, "Age"))+" years old!");
c+=1;
}
Edited by famous, 12 July 2012 - 12:47 PM.











