You are currently viewing the GMLscripts.com static mirror. Forum access and script submissions are not available through this mirror.

Invert GMLscripts.com

ds_list_select_relative_wrap

Returns a value from a list data structure in a position relative to a given value. If a relative position is beyond extents of the list, the position is wrapped around until it is within range. If current value isn't among the choices, return value is undefined.

//  list == { "Hello", "Doctor", "Name" }
val = ds_list_select_relative_wrap("Name", -2, list);  //  val == "Hello"
val = ds_list_select_relative_wrap("Name", 2, list);   //  val == "Doctor"
ds_list_select_relative_wrap(current,delta,list)
Returns a value from a list data structure in a position relative to a given value.
COPY/// ds_list_select_relative_wrap(current,delta,list)
//
//  Returns a value from a list data structure in a position relative 
//  to a given value. If a relative position is beyond extents of the
//  list, the position is wrapped around until it is within range. If
//  current value isn't among the choices, return value is undefined.
//
//      current     value matching a given choice
//      delta       relative position of desired choice, integer
//      list        list of values to return, if selected
//
//  eg. list == { "Hello", "Doctor", "Name" }
//      ds_list_select_relative_wrap("Name", -2, list) == "Hello"
//      ds_list_select_relative_wrap("Name", 2, list) == "Doctor"
//
/// GMLscripts.com/license
{
    var current = argument[0];
    var delta = argument[1];
    var choices = argument[2];
    var size = ds_list_size(choices);
    i = ds_list_find_index(choices, current);
    if (i < 0) return undefined;
    i = (((i + delta) mod size) + size) mod size;
    var result = ds_list_find_value(choices, i);
    return result;
}

Contributors: xot

GitHub: View · Commits · Blame · Raw