<RetVar> = array alloc: size = <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> = array alloc: size = <Var/Number>

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

<RetVar> = array alloc: size= <Var/Number>


<RetVar> = The name you wish to give the array and the variable it will be stored in.
<Var/Number> = The size you wish the new array to be. This is the number of internal 'elements' to the array.


Creates and allocates an array with <Var/Number> elements and assigns the result to <RetVar>.
The size can be zero, which will give you an array with no elements (an empty array) – this array can be later appended to.

Arrays are always zero based (the first element is element zero).

Mulitiple arrays can be inside an array (an array of arrays).
These internal arrays can be created at the time the master array is created or they can be from a variety of sources, anywhere you get an array as a return for example.


Example array structures;

Example: 1,
This creates a single empty array
$master.array =array alloc: size = 0


Example: 2,
This creates an array with 4 internal arrays

First, create all the arrays,

Create main array
$master.array =array alloc: size = 4

Create sub arrays
$sub.array.1 =array alloc: size = 0
$sub.array.2 =array alloc: size = 0
$sub.array.3 =array alloc: size = 0
$sub.array.4 =array alloc: size = 0

Then place them where they need to be,

$master.array [ 0 ] = $sub.array.1
$master.array [ 1 ] = $sub.array.2
$master.array [ 2 ] = $sub.array.3
$master.array [ 3 ] = $sub.array.4

To retrieve the internal arrays, you would use,

$sub.array.1 = $master.array [ 0 ]
$sub.array.2 = $master.array [ 1 ]
$sub.array.2 = $master.array [ 2 ]
$sub.array.4 = $master.array [ 3 ]

The important thing about arrays is, that they are pointers to the actual data contained in them.
If two separate scripts grab $master.array from the same global variable, then both are simultaneously accessing the exact same physical array and not copies of it.
If one of these scripts does a $master.array = null then the other script will be completely unaffected.
All this script did was to sever it's link to the place where the array's data is stored.
To delete the data inside an array you have to use array functions like remove item or resize array.


Command Location:

Alex Vanderbilt
Winner X3 Sektorquest
Posts: 2127
Joined: Thu, 4. May 06, 12:07
x3tc

[TiP][49] 286695

Post by Alex Vanderbilt » Sun, 3. Oct 10, 16:35

<RetVar> = array alloc: size= <Var/Number>

<RetVar> = Der Name, den man dem Array (hier Feld oder Bereich) zuweisen möchte, und der die Variable benennt, in dem die Informationen gespeichert werden.
<Var/Number> = Die Größe des Arrays. Diese Nummer legt fest, wie viele Elemente das Array beinhalten kann.

Erstellt und reserviert ein Array mit <Var/Number> Elementen und weißt das Ergebenis <RetVar> zu.
Die Größe des Arrays kann 0 betragen, was dann eine Matrix ohne Inhalt bereitstellt, welches im Nachhinein erweitert werden.

Arrays basieren immer auf 0. Das erste Element in einem Array ist immer 0.

In einem Array können auch mehrere Arrays exisiteren (Ein Array in einem Array). Diese internen Arrays können zu dem Zeitpunkt erstellt werden, wenn das Masterarray (Überbereich) erstellt wird, oder aber können eine Vielzahl von Quellen darstellen, wo man als Rückgabe ein Array erhält.

Beispiele für Array-Strukturen:

Beispiel #1:

$master.array =array alloc: size =0

Hier wird ein einfaches, leeres Array erstellt.

Beispiel #2:

Hier wird ein Array mit 4 internen Arrays erstellt:

Zu erst werden alle Arrays erstellt.

Create main array
$master.array =array alloc: size = 4

Create sub array
$sub.array.1 =array alloc: size = 0
$sub.array.2 =array alloc: size = 0
$sub.array.3 =array alloc: size = 0
$sub.array.4 =array alloc: size = 0

Platziere die Arrays dann dort, wo sie benötigt werden.

$master.array [ 0 ] = $sub.array.1
$master.array [ 1 ] = $sub.array.2
$master.array [ 2 ] = $sub.array.3
$master.array [ 3 ] = $sub.array.4

Um die internen Arrays abzufragen, verwendet man den folgenden Kode:

$sub.array.1 = $master.array [ 0 ]
$sub.array.2 = $master.array [ 1 ]
$sub.array.2 = $master.array [ 2 ]
$sub.array.4 = $master.array [ 3 ]

Das wichtige bei Arrays ist, das sie Anzeiger zu der tatsächlich in ihnen gespeicherten Informationen sind.
Wenn zwei verschiedene Skripte auf $master.array zugreifen, dann greifen sie auf das physikalisch exakt gleiche Array zu und nicht etwa auf Kopien.
Wenn ein Skript ein $master.array = null ausgibt, dann bleiben andere Skripte, die auch auf dieses Array zu greifen, unbeeinflusst davon.
Mit dieser Aktion hat das betreffende Skript einzig seine Verbindung zum Speicherort der im Array gespeicherten Informationen unterbrochen.
Um Informationen in einem Array zu löschen, muss man Array-Funktionen wie etwa remove item oder resize array verwenden.


Zu finden unter:

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

[39]286695

Post by Juggernaut93 » Sun, 22. Jul 12, 11:53

<RetVar> = array alloc: size= <Var/Number>


<RetVar> = Il nome che vuoi assegnare all'array e la variabile in cui sarà contenuto.
<Var/Number> = La dimensione che vuoi attribuire al nuovo array. È il numero di elementi interni dell'array.


Crea e alloca un array con <Var/Number> elementi e assegna il risultato a <RetVar>.
La dimensione può essere zero, dandoti così un array senza elementi (un array vuoto), che in seguito potrà essere esteso.

Gli array sono sempre a base zero (cioè il primo elemento è l'elemento numero zero).

Ci possono essere array multipli all'interno di un array (ovvero un array di array).
Questi array interni possono essere creati dopo aver creato l'array principale o possono essere generati da varie fonti, ad esempio da ovunque tu ottenga un array come valore di ritorno.


Esempi di strutture di array:

Esempio 1:
Crea un singolo array vuoto
$master.array = array alloc: size= 0


Esempio 2:
Crea un array con 4 array interni

Per prima cosa, si creano tutti gli array

Si crea l'array principale
$master.array = array alloc: size= 4

Si creano i sotto-array
$sub.array.1 = array alloc: size= 0
$sub.array.2 = array alloc: size= 0
$sub.array.3 = array alloc: size= 0
$sub.array.4 = array alloc: size= 0

Poi si posizionano dove devono stare

$master.array [ 0 ] = $sub.array.1
$master.array [ 1 ] = $sub.array.2
$master.array [ 2 ] = $sub.array.3
$master.array [ 3 ] = $sub.array.4

Per ottenere gli array interni si usa

$sub.array.1 = $master.array [ 0 ]
$sub.array.2 = $master.array [ 1 ]
$sub.array.3 = $master.array [ 2 ]
$sub.array.4 = $master.array [ 3 ]

La cosa importante per quanto riguarda gli array è che essi sono puntatori ai reali dati in essi contenuti.
Se due script separati assegnano il valore a $master.array dalla stessa variabile globale, essi stanno accedendo simultaneamente allo stesso array fisico e non a sue copie.
Se uno di questi script imposta $master.array = null, gli altri script non ne saranno minimamente influenzati.
Con questa azione lo script in questione ha interrotto il suo collegamento con il posto delle informazioni memorizzate nell'array.
Per cancellare i dati all'interno di un array devi usare le funzioni per array come "remove item" o "resize array".


Posizione dell'istruzione nella lista:

Locked

Return to “MSCI Reference”