EnglishGermanFrenchRussianItalianSpanish
Log inRegister
 
<RetVar> = array alloc: size = <Var/Number>
Post new topic This topic is locked: you cannot edit posts or make replies.
View previous topic :: View next topic
Author Message
mark_a_condren





Joined: 03 Aug 2005
Posts: 1385 on topic
Location: Newcastle - Australia
Thank you for registering your game
PostPosted: Sat, 11. Sep 10, 11:31    Post subject: <RetVar> = array alloc: size = <Var/Number> Reply with quote Print

<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:



Back to top
View user's profile Send private message Send e-mail
Alex Vanderbilt
Winner X3 Sektorquest


MEDALMEDAL

Joined: 04 May 2006
Posts: 2114 on topic

Thank you for registering your game
PostPosted: Sun, 3. Oct 10, 16:35    Post subject: [TiP][49] 286695 Reply with quote Print

<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:



Back to top
View user's profile Send private message
Juggernaut93



MEDAL

Joined: 17 Jul 2011
Posts: 2297 on topic
Location: DeVries/Verità Accecante/Corona Ardente
Thank you for registering your game
PostPosted: Sun, 22. Jul 12, 11:53    Post subject: [39]286695 Reply with quote Print

<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:



Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic This topic is locked: you cannot edit posts or make replies.
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum
Control Panel
Login Data
The time now is Wed, 22. Nov 17, 14:48

All times are GMT + 2 Hours


Board Security

Copyright © EGOSOFT 1989-2017
Powered by phpBB © 2001, 2005 phpBB Group
Template created by Avatar & BurnIt!
Debug: page generation = 0.74890 seconds, sql queries = 17