Loops scripting tutorial (Page 3 of 4)

Written by Roguey,

Loops scripting tutorial, written by Roguey


Adding spaces

Okies... now we have a completed while loop, we need to add so code into the middle of the loop. Oh heck... theres no spaces to add anything, am I doomed? ... I dont have to re-write this script again? Do i??... No you dont, you simply need to be able to add new blank lines to your script. By default the insert key is used however if your keyboard is anything like mine.. well.. its not on my keyboard. So lets bind a better key, so we can add new lines. If however your keyboard does have an Insert key where home, end, page up and page down is, then you can skip this section and move onto Back to our loop.

Save your script and exit all the way out of the script editor and into your game (by pressing escape). Once you see the basic game control, ie. this:

Eject, Pilot, Property, Ship etc.

Now select Options, then Controls, then right arrow until you reach Script editor. Once in the script editor list, look for Insert command/argument:

The script Editor Controls list

Now check to see if you have that key on your board, I have already reset mine to use the zero on the numpad, as my keyboard doesnt have the insert key. If dont have that key on your keyboard, I recommend you change the binding to use the zero on your numberpad. Make sure your controls (you only need to do this once).

Okies, we got that binding setup, now head back to the script editor. However once on the page with all the scripts, you need to look for our Make.Sat script. Once you have found it, press enter to edit the script.

Back to our loop

We now need to add some code just before the inc command. Press the key you have assigned for Insert command/argument (either insert or numpad zero). Your script should look like this:

Our while loop with an inserted blank line

Now press enter, we want to be able to get a sector from the x and y cords.
So goto Universe and Sector Commands, then add this command to your script:

<RefVar/IF> get sector from universe index: x=<Var/Number>, y=<Var/Number>

When your asked a for return value, select <Variable> and name it sector. Once back in your script, set x=<?> to x and y=<?> to y (x and y are both under the available variables). So you should have the following statement:

Our sat script so far

However when we add our satellites, we will be adding them to every sector (including ones that dont exist in our game). So lets do things correct and check to see if the sector we got, actually exists! So under our get sector command, add a new line. Now add (in the General Object Commands section) <RefVar/IF><RefObj> exists (7th down) command to our script. After adding, select if (under script input). This should read as if <?> exists. You need to change the <?> to variable name sector.

so what this does is to check to see if this sector really exists in our universe. We now need to add what happens if the sector exists. So insert two blank lines (under our get sector from command). On the first blank line, add create ship (found in General Object Commands) and set its return variable to sat. On the second blank line, add end (found under General then Flow control - it will be called end conditional their). When done it should look something like this:

Our sat script so far

If you remmeber from my previous script guide, we need to set some parameters for our create ship command. You need to change the ship type to Advanced satellite, Owner to player (which is pilot name under the Goner race list), addto to the variable sector and x/y/z to the number 0. Once done it should look something like this:

Nearly done...

Next: Adding the second loop
<< Previous Page - Next Page >>