Login   ·   Register   ·   Account help   ·   Privacy policy   ·   Contact

Arrays scripting tutorial (Page 2 of 5)

Written by Roguey,

Arrays scripting tutorial, written by Roguey

Coding an array

So lets start making this code, head to <New Line> and press enter. This time we are looking for a command to return array of ships. We are luckly enough to have one already in X3/TC, under Universe and Sector Commands (its about a page down). It looks like this:

<RetVar> = get ship array: of race <Var/Race> class/type= <Value>

Add it to our code and select Script input to ships. So what does this do? Well this command searches the whole of the galaxy looking for ships that belong to a certain race, then can be filtered by class (ie. M1/M2 etc. or type Fighter/Ship) etc.

As we want to know how many ships the Argon Government has, set race <Var/Race> to Argon (high-light <Var/Race>, enter, select race, Argon). The next parameter to set is the type, as we want to know about all the Argon ships, so we need to set this to Ship (Press enter on class/type= <Value>), then scroll down to list until you reach Select Object Class. Press enter and select Ship (top of the list). You script should look like this:

Our Count.Ships script, so far

So now ships is an array of all the Argon ships, we next need to count how many ships are in there. This is done by another command called size of array. So next, back to <New Line> and press enter. The count array command should be found in General Commands, then Arrays. Once there you need to add this command:

<RetVar/IF> size of array <Var/Array>

Now set the Script Input to <Variable>, then ships.count. Now the last parameter of the size of array should be selected (ie. <?>), press enter and change it to ships under Available Variables. You should now have the following:

Our Count.Ships script, so far

The next thing to do is to tell the player the value inside ships.count, however before we do that we need to form a message. Simply reporting a number to someone isnt very helpful. So back to <New Line> enter, General Commands, then add <RetVar/IF><Expression>. When ask for script input, select <Variable> then type in msg. So we should have $msg = <?>. Now press enter on the first <?> and find <String> under Script Input. When add a string, we will be asked for some text. Please type in There are and press enter (it will look better if you add a space after are. Yes, I know this doesnt make sense... yet, but its not finished. You should have 3 dots selected now (ie. in red). So press enter and find the + symbol under operators, add it. Once again press enter on the next 3 dots and select ship.count (under Available Variables). Now add another + symbol. Nearly done.. on the last 3 dots, scroll down to <String> once again, add type Argon ships in the galaxy (add a space before Argon). So after all that you should have:

Our Count.Ships script, so far

The next step, telling the player the answer!

Next: Sending a message
<< Previous Page - Next Page >>