Login | Register

Sorting values

August 6, 2006, 21:24 by Calle
[loading]
-->
<b>ds_list_create() </b>Creates a new list. The function returns an integer as an id that must be used in all other functions to access the particular list.
<b>ds_list_destroy(id) </b> Destroys the list with the given id, freeing the memory used. Don't forget to call this function when you are ready with the structure.
<b>ds_list_clear(id) </b> Clears the list with the given id, removing all data from it but not destroying it.
<b>ds_list_size(id) </b> Returns the number of values stored in the list.
<b>ds_list_empty(id) </b> Returns whether the list is empty. This is the same as testing whether the size is 0.
<b>ds_list_add(id,val) </b> Adds the value at the end of the list.
<b>ds_list_insert(id,pos,val) </b> Inserts the value at position pos in the list. The first position is position 0, the last one the size minus 1.
<b>ds_list_replace(id,pos,val) </b> Replaces the value at position pos in the list with the new value.
<b>ds_list_delete(id,pos) </b> Deletes the value at position pos in the list. (Position 0 is the first element.)
<b>ds_list_find_index(id,val) </b> Find the position storing the indicated value. If the value is not in the list -1 is returned.
<b>ds_list_find_value(id,pos) </b> Returns the value stored at the indicated position in the list.
<b>ds_list_sort(id,ascend) </b> Sorts the values in the list. When ascend is true the values are sorted in ascending order, otherwise in descending order.

These are my favourite functions for ranking and sorting values. Handling integers has never been easier. You may load an entire high score list into this data structure system.

<b>ds_list_sort(id,ascend)</b> is the key function for sorting. I think that, thanks to the quote straight from the manual that it should be pretty easy to use it and understand what I mean. Anyway, if you have a question please ask it!

Comments

Loading comments... [loading]
.
Users logged in:

game maker articles, game maker examples, game maker tutorials, gmtutorials, game maker questions and answers, game maker crash course, how to create games