ds_map_find_previous

Finds and returns the previous key in the ds_map above the one specified in the function.

Syntax:

ds_map_find_previous(id, key);


Argument Description
id The id of the map to use.
key The key to find the previous one to.


Returns: Real, string or undefined


Description

This function returns the previous key stored in the ds_map before the one specified in the function. This can be useful if your have to iterate through the ds_map looking for something, but should be avoided if possible as it can be slow. If no such key exists then the function will return <undefined>. You should always check this using the is_undefined() function.


Example:

var size, key, i;
size = ds_map_size(inventory) - 1;
key = ds_map_find_last(inventory);
for (i = size; i > 0; i --;)
   {
   if key != "gold" key = ds_map_find_previous(inventory, key) else break;
   }

The above code creates some temporary variables and then gets the ds_map size and finds the last key as stored by the computer in the map. It then uses a for loop to iterate back through the ds_map looking for the key value "gold". If it finds it, it breaks out the loop.


Back: DS Maps
Next: ds_map_find_value
© Copyright YoYo Games Ltd. 2018 All Rights Reserved