<RetVar/IF> find <Value> in array: <Value>

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/IF> find <Value> in array: <Value>

Post by mark_a_condren » Tue, 14. Sep 10, 18:35

[skip|else] if [not]|while [not] <RetVar/IF> find <Value> in array: <Value>


[skip|else] if [not]|while [not] = Possible 'conditional' statements that can be used with this command.
<RetVar/IF> = Command return, with an 'if' statement used it will be TRUE (1) if condition passes or FALSE (0) if it fails, otherwise if you use a Variable it will be the value of TRUE / FALSE as an integer.
<Value> = The value you wish to check for.
<Value> = The array that you want to check the contents of.


Returns TRUE if the value is found.


Example:

Ok, let pretend that you want to create a list (array) containing all the different wares that are on ships that you own in your empire. This list only needs to have the entry for each ware in it once.

So, using appropriate commands you could get a list of all your ships, then cycle each one individually and get the wares onboard each ship.

Before you start to cycle all your ships you would create an array to hold the list of individual wares,

$ships.wares.list = array alloc: size = 0

While cycling the wares list you could put,

skip if find $ships.ware in array: $ships.wares.list
| append $ships.ware to array: $ships.wares.list

This would check first to see if that particular ware is already in the $ships.wares.list array, and if it finds it it would continue on but if it doesn't find it it will append the ware to the list. This would result in a list containing only one entry for each ware, but all ships wares would have been checked.


Command Location:

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

[TiP][49] 286908

Post by X2-Illuminatus » Sun, 10. Oct 10, 00:13

[skip|else] if [not]|while [not] <RetVar/IF> find <Value> in array: <Value>


[skip|else] if [not]|while [not] = Die möglichen bedingten Anweisungen, die mit diesem Befehl genutzt werden können.
<RetVar/IF> = Rückgabewert des Befehls, mit einer 'if' Anweisung wird dieser TRUE (1) (wahr) sein, wenn die Bedingung erfüllt ist oder FALSE (0) (falsch), wenn nicht. Andernfalls, wenn eine Variable genutzt wird, wird der Wert von TRUE / FALSE als ganze Zahl zurückgegeben.
<Value> = Der Wert, nach dem gesucht werden soll.
<Value> = Das Array, dessen Inhalt überprüft werden soll.


Gibt TRUE zurück, wenn der Wert gefunden wurde.


Beispiel:

Okay, lass uns annehmen du möchtest eine Liste (Array) erstellen, die alle Waren beinhaltet, die auf den Schiffen deines Imperiums vorhanden sind. Diese Liste benötigt nur je einen Eintrag für jede Ware.

Indem du entsprechende Befehle nutzt, kannst du eine Liste aller deiner Schiffe erhalten. Diese kannst du nun einzeln durchgehen, um die Waren, die jedes Schiff an Bord hat, zu bekommen.

Bevor du damit anfängst alle Schiffe einzeln zu überprüfen, würdest du dir ein Array erstellen, das die Liste der einzelnen Waren enthält:

$ships.wares.list = array alloc: size = 0

Während du die Warenliste durchgehst, kannst du folgendes machen:

skip if find $ships.ware in array: $ships.wares.list
| append $ships.ware to array: $ships.wares.list

Dies überprüft zunächst, ob die entsprechende Ware bereits im Array $ships.wares.list vorhanden ist. Wenn die Ware gefunden wird, wird es einfach weitergehen. Wenn die Ware nicht gefunden wird, wird sie zur Liste hinzugefügt. Dies würde eine Liste ergeben mit jeweils nur einem Eintrag pro Ware, aber alle Waren der Schiffe wären überprüft worden.


Zu finden unter:

Locked

Return to “MSCI Reference”