DS Lists

A DS list is a data structure that stores information sequentially as it is added (much like an array). DS lists are very flexible data structures that permit you to add values at the end or insert them somewhere in the middle of the list, as well as giving you the ability to shuffle the order (to randomise the values) or sort them in an ascending or descending order.

NOTE It is recommended to use arrays over DS lists as they have similar features, are easier to use and are garbage collected automatically.

When accessing DS list data structures, you should always try to use integer values for the list position, and all non-integer indices will be floored by GameMaker if you do not. If that is not what you require, then you will need to do the rounding yourself previously before passing the index that you wish to check.

NOTE As with all dynamic resources, data structures take up memory and so should always be destroyed when no longer needed to prevent memory leaks which will slow down and eventually crash your game.

Apart from the specific functions listed below you can all use an expression (called an accessor) to add or modify the contents of your DS list. This accessor looks similar to a 1D array with the following syntax:

list_index[| index]

You can find more information, plus examples, from the GML Overview page on Accessors.

Function Reference

General

Serialisation

JSON

DS lists can be used hold DS maps and other DS lists too, and so we have some special functions that are used to "flag" or "mark" positions within the list as holding these data structures. In general this is not required, but it has the advantage of automatically garbage collecting (destroying) the marked data structures when the parent list is destroyed, and it's also required when used in conjunction with the json_encode function so that the list and its data are properly encoded. The functions for this are: