<RetVar> = clone array <Var/Array>: index <Var/Number> … <Var/Number>

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> = clone array <Var/Array>: index <Var/Number> … <Var/Number>

Post by mark_a_condren » Sat, 11. Sep 10, 17:31

<RetVar> = clone array <Var/Array>: index <Var/Number> ... <Var/Number>


<RetVar> = The new array containing the selected contents.
<Var/Array> = The array to retrieve the contents from.
<Var/Number> = The first element of the required contents.
<Var/Number> = The last element of the required contents.


Creates a new array, assigning it to <RetVar> with the required contents of <Var/Array>. The starting element being the first <Var/Number> and ending element being the second <Var/Number>.
This new array is allocated when this instruction executes, so a previous call to <RetVar> = array alloc: size = <Var/Number> is unnecessary.

The resulting clone is independant of the source array, which is kind of the whole point of this command. This however dose have some ... Quirks ... see example 2.


Examples:

Example 1.

$clone.array = clone array $array.1 : index 5 ... 10

$clone.array will be a new array containing elements 5, 6, 7, 8, 9 and 10 from array $array.1.

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

Example 2.

As described in this topic, arrays copied via normal assignment ($array2 = $array1) share their data.
The clone array command on the other hand, will create an independant copy by copying every element of the source array.
It's important to note, that if an element of the source array is itself an array, the data of this nested array will again be shared between the source and the cloned array.
An example should clarify this:

$nested = create new array, arguments='I'm nested', null, null, null, null
$array = create new array, arguments=1, 2, 3, $nested, null
$clone = clone array $array: index 0 ... 3
$clone[3][0] = 'I'm nested and shared'

$str = $array[3][0]
write to player logbook $str

This will write 'I'm nested and shared' to the logbook, although you cloned the top-level array.


Command Location:
  • »» General Commands
    • »» Arrays
      <RetVar> = clone array <Var/Array>: index <Var/Number> ... <Var/Number>
Last edited by mark_a_condren on Fri, 31. Dec 10, 12:51, edited 3 times in total.

User avatar
Juggernaut93
Posts: 2897
Joined: Sun, 17. Jul 11, 21:03
x4

[39]286717

Post by Juggernaut93 » Mon, 3. Sep 12, 18:17

<RetVar> = clone array <Var/Array>: index <Var/Number> ... <Var/Number>


<RetVar> = Il nuovo array contenente i contenuti selezionati.
<Var/Array> = L'array da cui recuperare i contenuti.
<Var/Number> = Il primo elemento dei contenuti richiesti.
<Var/Number> = L'ultimo elemento dei contenuti richiesti.


Crea un nuovo array assegnandolo a <RetVar> con i contenuti richiesti di <Var/Array>. L'elemento iniziale è il primo <Var/Number>, mentre l'elemento finale è il secondo <Var/Number>.
Questo nuovo array viene allocato quando quest'istruzione viene eseguita, perciò non è necessaria una precedente chiamata a <RetVar> = array alloc: size = <Var/Number>.

Il clone risultante è indipendente dall'array sorgente, che è un po' il punto centrale di questo comando. Ci sono però alcune particolarità (vedi l'esempio 2).


Esempi:

Esempio 1.

$clone.array = clone array $array.1 : index 5 ... 10

$clone.array sarà un uovo array contenente gli elementi 5, 6, 7, 8, 9 e 10 dell'array $array.1.

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

Esempio 2.

Come descritto in questo topic, gli array copiati tramite normale assegnazione ($array2 = $array1) condividono i loro dati.
Il comando 'clone array', d'altronde, creerà una copia indipendente copiando ogni elemento dell'array sorgente.
È importante notare che, se un elemento dell'array sorgente è esso stesso un array, i dati di questo array nidificato saranno ancora una volta condivisi tra l'array sorgente e l'array clonato.
Un esempio dovrebbe chiarire tutto ciò:

$nested = create new array, arguments='I'm nested', null, null, null, null
$array = create new array, arguments=1, 2, 3, $nested, null
$clone = clone array $array: index 0 ... 3
$clone[3][0] = 'I'm nested and shared'

$str = $array[3][0]
write to player logbook $str

Ciò scriverà 'I'm nested and shared' nel diario di bordo, sebbene tu abbia copiato l'array di livello superiore.


Posizione dell'istruzione nella lista:
  • »» General Commands
    • »» Arrays
      <RetVar> = clone array <Var/Array>: index <Var/Number> ... <Var/Number>

Locked

Return to “MSCI Reference”