<RetVar> = get index of <Value> in array <Var/Array> offset = <Var/Number> + 1

This forum serves as MSCI Reference at EGOSOFT. It's Read-Only for non MSCI Group members.

Moderators: Scripting / Modding Moderators, MSCI Moderators

Locked
mark_a_condren
Posts: 1468
Joined: Wed, 3. Aug 05, 05:05
x3tc

<RetVar> = get index of <Value> in array <Var/Array> offset = <Var/Number> + 1

Post by mark_a_condren » Mon, 13. Sep 10, 20:55

<RetVar> = get index of <Value> in array <Var/Array> offset = <Var/Number> + 1


<RetVar> = The value returned by this command.
<Value> = The value you want the index of.
<Var/Array> = The array you want the index from.
<Var/Number> = Specifies the starting index, from where the command will search the array for the given <Value>.



Returns the position of the element <Value> in a specified array <Var/Array>.
This position can have a specified offset <Var/Number> +1, this becomes necessary when multiple indexes in the array have the same value.

Choosing "null" as value for "offset" has the same effect as choosing -1 (in other words: The first index will be considered, even if you choose "null").


Examples:

$value = 5

$index = get index of $value in array $this.array offset = -1 + 1

remove element from array $this.array at index $index

The above example would find the required index of the selected value and then the return from that command could be used to specify which index is to be removed from the selected array.
The -1 is used in this example to allow searching from the first index of the array (which is 0 = -1 + 1).
If the 'get index' command can not find the required value in the selected array it returns -1.

--------------------------------------------------------------

$array = create new array, arguments=1, 2, 1, 3, 1
$index1 = get index of 1 in array $array offset=-1 +1
(* $index1 == 0, since $array[0] == 1 and offset == 0 (-1 + 1 = 0) )

$index2 = get index of 1 in array $array offset=$index1 +1
(* $index2 == 2, since $array[2] == 1 and offset == 1 ($index1 + 1 = 1) )

$index3 = get index of 1 in array $array offset=$index2 +1
(* $index3 == 4, since $array[4] == 1 and offset == 3 ($index2 + 1 = 3) )


Related Commands:

remove element from array <Var/Array> at index <Var/Number>


Command Location:
  • »» General Commands
    • »» Arrays
      <RetVar> = get index of <Value> in array <Var/Array> offset = <Var/Number> + 1
Last edited by mark_a_condren on Tue, 22. Feb 11, 09:18, edited 4 times in total.

User avatar
X2-Illuminatus
Moderator (Deutsch)
Moderator (Deutsch)
Posts: 24949
Joined: Sun, 2. Apr 06, 16:38
x4

[TiP][49] 286856

Post by X2-Illuminatus » Thu, 14. Oct 10, 17:08

<RetVar> = get index of <Value> in array <Var/Array> offset = <Var/Number> + 1


<RetVar> = Der Rückgabewert dieses Befehls.
<Value> = Der Wert, dessen Stelle du bestimmen möchtest.
<Var/Array> = Das Array, von dem du die Stelle haben möchtest.
<Var/Number> = Erlaubt die Startposition im Array festzulegen, von der aus der gegebene Wert <Value> gesucht wird.


Gibt die Position des Elements <Value> in einem gewählten array <Var/Array> zurück.
Diese Position kann um den festgelegten Wert <Var/Number> +1 verschoben werden. Dies ist nötig, wenn der gleiche Wert im Array an mehreren Stellen vorhanden ist.


Beispiel:

$value = 5

$index = get index of $value in array $this.array offset = -1 + 1

remove element from array $this.array at index $index

Das obige Beispiel würde die Stelle des gewählten Wertes finden und der Rückgabewert des Befehls könnte dann genutzt werden, um festzulegen, welche Stelle aus dem gewählten Array entfernt werden soll
Die -1 wird in diesem Beispiel genutzt, um von der ersten Stelle des Arrays (0 = -1 + 1) suchen zu können.
Wenn der 'get index'-Befehl den benötigten Wert im gewählten Array nicht finden kann, wird er -1 zurückgeben.

--------------------------------------------------------------

$array = create new array, arguments=1, 2, 1, 3, 1
$index1 = get index of 1 in array $array offset=-1 +1
(* $index1 == 0, since $array[0] == 1 and offset == 0 (-1 + 1 = 0) )

$index2 = get index of 1 in array $array offset=$index1 +1
(* $index2 == 2, since $array[2] == 1 and offset == 1 ($index1 + 1 = 1) )

$index3 = get index of 1 in array $array offset=$index2 +1
(* $index3 == 4, since $array[4] == 1 and offset == 3 ($index2 + 1 = 3) )


Ähnliche Befehle:

remove element from array <Var/Array> at index <Var/Number>


Zu finden unter:
  • »» General Commands
    • »» Arrays
      <RetVar> = get index of <Value> in array <Var/Array> offset = <Var/Number> + 1
Last edited by X2-Illuminatus on Tue, 4. Jan 11, 18:32, edited 1 time in total.

Locked

Return to “MSCI Reference”