MoveElement

List command

Syntax

Moves the current element to another place in the same list. It stays the current element.

MoveElement(<list>(), <where> [, <position>])

Parts

<list>A list declared with NewList, written with its empty parentheses: scores().
<where>#AK_LIST_FIRST (to the start), #AK_LIST_LAST (to the end), #AK_LIST_BEFORE or #AK_LIST_AFTER (before or after the element at <position>).
<position>Required with #AK_LIST_BEFORE and #AK_LIST_AFTER, ignored otherwise. The position of the reference element, counted before the move.

Good to know

  • Returns nothing: write it on its own line.
  • With no current element, the program stops with "MoveElement requires a current list element". An unknown <where> or a <position> outside the list also stops it.
  • Leaving out <position> with #AK_LIST_BEFORE or #AK_LIST_AFTER compiles, then stops the program AND loses the current element: it is taken out of the list and never put back. Always give the position.
  • Coming from PureBasic: the reference element is a position, not an element pointer.

Example

NewList a.integer()FOR k = 1 TO 5  AddElement(a())  a() = kNEXTSelectElement(a(), 4)MoveElement(a(), #AK_LIST_BEFORE, 1)Console(Str(a()) + " at " + Str(ListIndex(a())))   ' 5 at 1FOREACH a()  Console(Str(a()))   ' 1, 5, 2, 3, 4NEXT
In the manual : Arrays, lists and maps