Login   ·   Register   ·   Account help   ·   Privacy policy   ·   Contact

Loops scripting tutorial (Page 2 of 4)

Written by Roguey,

Loops scripting tutorial, written by Roguey


Building a loop

Okies, now we got our basic two variables set, we now need to make a loop. In X3 / Terran conflict there are no For loops, just while loops. While loops are fine for everything we need! So back to <New Line> and go into General Commands, again we want <RetVar/IF><Expression>, so add it to our script but this time select while at the bottom of the list. You now should have while <?> ... on line number 3. So now we must add some parameters to our while loop.

If not already select, high-light <?> (after the while), then press enter. Select x under available variables. You should have something like this:

While $x ...

At this point we can not save this script, so please dont try now. This is because our script makes no sense. We need to add some extra information to this while loop to make it complete. To do this make sure the three dots are high-lighted and press enter. Next add the less than sign (ie. < - under operators). So now we have while $x <. This still makes no sense, so we need to add another parameter to this while statement. So once again press enter on the three dots, but this time add <Number>. Lets make it 30 for now. So you should have the following:

While $x < 30 ...

However we are still not finished with this loop - its still in-complete! To finish this while loop we need to do two more things: increase x by one each time we go through this loop, and the next tell the script editor where the end of this loop is.

So to increase x by 1, head back to <New Line>, General Commands now look for inc <RetVar> =, ie:

inc <RetVar> =, dec <RetVar> =

So what do these two commands do?.. well inc adds 1 to a variable, whilst dec minuses 1 from a variable. In our loop we are checking when X is greater than 30, so we need to add the inc <RetVar> = command to our script. It will ask for a script input, choose the variable, x.

Okay... just one more thing to complete our while loop - the end. Back to <New Line> then General Commands, followed by Flow Control. Now add end conditional to our script. This should now complete our while loop, so we be able to save our script now! Your script should look something like this:

Our finished while loop

Next: Adding spaces
<< Previous Page - Next Page >>