gosub <Label>

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

gosub <Label>

Post by mark_a_condren »

gosub <Label>


<Label> = A predefined 'label' in your script.


Allows you to define the name and location of a <Label> that is used as the jump destination for a gosub statement.
When a gosub statement is encounted the script will jump to the location of the <Label> and continue on until the first endsub is reached and then return to the position directly under the gosub statement.

The 'sub' part of the name implies a downward direction, however, 'gosub' intructions can be jumps in an upwards direction in your script.

Example:

write to player logbook = 1
write to player logbook = 2

gosub mix.numbers
write to player logbook = 3
write to player logbook = 4

return null

mix.numbers:
write to player logbook = 5
endsub


In this case the numbers would be written to the logbook in the following order, 1, 2, 5, 3 and 4 due to the 'gosub' causing 3 and 4 to be put after 5. (5 would not be written twice due to the 'return null' being encountered)


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

[TiP][49] 286646

Post by Alex Vanderbilt »

gosub <Label>

<Label> = Eine vordefinierte Bezeichnung oder Markierung in einem Skript.

Dieses Kommando erlaubt es, eine Bezeichnung/Markierung oder Stellenangabe eines <Label>, die als Sprungziel einer gosub-Aussage dient. Sobald eine gosub-Aussage im Kode entdeckt wird, springt das Skript zu dem im <Label> angegebenen Punkt und setzt da die Verarbeitung des Kodes fort bis ein "endsub" gefunden wird. Nach dem "endsub" kehrt das Skript zu der Kodezeile zurück, der direkt auf die gosub-Aussage folgt.

Der "sub"-Teil im Namen impliziert eine nach unten gerichtete Bewegung. Allerdings könnten gosub-Anweisungen auch nach oben im Skript springen.

Beispiel:

write to player logbook = 1
write to player logbook = 2

gosub mix.numbers write to player logbook = 3
write to player logbook = 4

return null

mix.numbers:
write to player logbook = 5
endsub

In diesem Fall würden die wie folgt in das Logbuch geschrieben: 1; 2; 5; 3 und 4, da aufgrund der gosub-Anweisung von 2 zu 5 gesprungen wird, und das Skript nach dem endsub wieder zu 3 und 4 zurückkehrt. Das "return null" verhindert, dass 5 doppelt in das Logbuch geschrieben wird.


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

[39]286646

Post by Juggernaut93 »

gosub <Label>


<Label> = Una 'label' predefinita nel tuo script.


Ti permette di definire il nome e la posizione di una <Label> che è usata come destinazione di salto per un'istruzione gosub.
Quando incontra un'istruzione gosub lo script salta alla posizione della <Label>, continua finché non raggiunge il primo endsub e poi ritorna alla posizione immediatamente sotto all'istruzione gosub.

La parte 'sub' del nome implica un salto verso il basso, comunque, però, le istruzioni 'gosub' possono saltare anche verso l'alto nel tuo script.

Esempio:

write to player logbook = 1
write to player logbook = 2

gosub mix.numbers
write to player logbook = 3
write to player logbook = 4

return null

mix.numbers:
write to player logbook = 5
endsub


In questo caso i numeri verrebbero scritti nel diario di bordo nell'ordine 1, 2, 5, 3, e 4 a causa del 'gosub' che fa in modo che il 3 e il 4 siano messi dopo il 5. (Il 5 non verrebbe scritto due volte perché si incontra l'istruzione 'return null')


Posizione dell'istruzione nella lista:
Locked

Return to “MSCI Reference”