SortStructuredList

List command

Syntax

Sorts a list of records on one of their fields, in place.

SortStructuredList(<list>(), <field>, <options> [, <start>, <end>])

Parts

<list>A list of records declared with NewList, written with its empty parentheses: foes().
<field>The field name, as text: "hp". Case does not matter. A field of a nested record is written with a dot: "pos.x". The field must hold a number or a string.
<options>Required. #AK_ORDER_LOW_TO_HIGH (0), #AK_ORDER_HIGH_TO_LOW (1), and #AK_ORDER_FOLD_CASE (2) to ignore the case of letters. Add them to combine.
<start>Optional. The position of the first element to sort, from 0.
<end>Optional, required with <start>. The position of the last element to sort, included.

Good to know

  • Returns nothing: write it on its own line.
  • After the sort there is no current element.
  • An unknown field stops the program with "Unknown BASIC structure field". A field that holds a record stops it with "SortStructuredList requires a numeric or string value".
  • A list of numbers or strings stops the program: use SortList().
  • Without <start> and <end>, the whole list is used. Giving only <start> compiles but stops the program with "BASIC collection range requires start and end". A range outside the list stops it with "BASIC collection range is out of bounds".
  • Coming from PureBasic: the field is given by name, as text, not by an offset and a type.

Example

TYPE Foe  name AS string  hp AS integerENDTYPENewList foes.Foe()AddElement(foes())foes().name = "orc"foes().hp = 30AddElement(foes())foes().name = "elf"foes().hp = 10SortStructuredList(foes(), "hp", #AK_ORDER_LOW_TO_HIGH)FOREACH foes()  Console(foes().name + " " + Str(foes().hp))   ' elf 10, orc 30NEXT
In the manual : Arrays, lists and maps