<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>
- »» Arrays