instance_select_by_order

Syntax:

instance_select_by_order(obj_or_instance_or_array_of_them, condition_string, condition_value, [numb_add]);
Argument name Type Description
obj_or_instance_or_array_of_them array|instance|object The instances, objects, or combination of them
condition_string string The condition for testing. The posible values can be:
condition_value any The value to compare against the instance order
numb_add integer The number to add before comparing the instance order with the condition

Returns: (array) The array with the instances

Description:

This will return an array of instances filtered by the specified condition given by the number of the instance inside the array.

For more info about obj_or_instance_or_array_of_them argument check instance_select

The internal process of selection is the following:

  • First, all instances of obj_or_instance_or_array_of_them are selected and numbered from 0 to n-1 (where n is the number of total instances)
  • Then, each instance number is compared using the condition_string and the condition_value
  • If the condition_string can be "mod", "%", "mod!", "%!", "!mod" or "!%" then the numb_add parameter is added to the number of the instance and then, compared using the condition and value.
  • Then, an array containing all the matched instances is returned.

For example: If you want to select all odd instances of the obj_box in the room (numbered from the top to the bottom):

var arr = instance_select_sort( obj_box, set_y); arr = instance_select_numb( arr, "!mod", 2);

It is the same that saying all instances which (n mod 2) != 0 You can also use "mod!", "!%" or "%!" for the same result.

Another example: Suppose that you want to select obj_box the instances which number (sorted from left to right in the room) is 1, 4, 7, 10, etc. That is the same that all instances which (n mod 3) + 1 == 0 So, the formula will be:

(n mod condition_value)+numb_add == 0

Then, you need to call:

var arr = instance_select_sort( obj_box, set_x); arr = instance_select_by_order( arr, "mod", 3, 1);

The last Example: if you want to select the firsts 16 obj_tree instances sorted from right to left

var arr = instance_select_sort( obj_tree, set_x, false); arr = instance_select_by_order( arr, "<", 16);

This will return an array with ALL the ids of the instances of the obj_tree which number is below 16. (remember that the numbers starts from zero)