Planet Creation Article
-/- PAGE 2 -/-


Line 29, declares the Variable Array used to house, or contain, the planet data extrapolated from the text sent by the Server in response to our sending CJ?QQ. Discussing Array's in general is beyond the scope of this Text, and there are people far more knowledgeable than me. 

setArray $Lines 10 1

A 2 Dimensional Array: the variable $Lines is declared with 10 Rows each containing 1 (one), element. As you can see from the picture on the right (Variable information as represented by TWX), Menu letters are stored along with Planet Class names such that $Lines[8] returns "H" and $Lines[8][1] will return (which includes the hidden ANSI Characters.)

How you use design arrays it totally up to you and over time you'll develop your own understanding or style of handling Data.  Case and point: I could have easily saved my data in one of two other methods:







Back to the script. So far,  we have parsed out the data we're looking for and now it's time to spit-it-out. 

Line 55, clears the screen followed by a couple additional Echo statements.

Line 59, is a While loop that cycles through the array. The variable $i, has already been set and provides for an excellent End-of-Data pointer into the $Lines Array. A little hint: I left out Bounds checking. Bounds checking involves testing variables to see if there's valid data in the $Lines Array with appropriate handling --in this case a test to determine if the variable $i, is greater then 1 (one), or a check to see if ($Lines[1] <> 0)

Line 60, is fairly straight forward. The end of this While-Loop (Lines 59 through 64),should resemble something like :

At this point the code sits and waits for user input (Line 64). Once a user hits a key, the Case is changed and the routine cycles through the Array matching input with the $Lines Array (Line 68). If a match is not found the script halts (Line 46).

Let's assume a user selects '<C>   Oceanic II' from the menu we now can proceed with the actual Planet Creation. Line 71 sends the requisite "u y" (Use Genesis Torpedo and Yes I am sure). at this point a few Triggers are set to anticipate some possible eventualities:


Brief translation:

Line 72- All went well, planet has been popped, execution jumps to Line 90
Line 73- The game maximum allowable planets has been reached. Script Halts.
Line 74- Your ship has ran out of Genesis Torpedoes. Script Halts.
Line 75- Sector's Overloaded. Script indicates that we do not want to abort and Pauses

You'll notice that the script executes another Pause once it indicates that we do not want to Abort overloading the Current Sector. For future reference, this is a very handy little 'trick' that can extend the power and efficiency of a lot of scripts.

Assuming all went well, execution will branch to Line 90, a planet has been created and now needs to be given a name. Luckily, the line we've triggered on also contains the Planet Class just created allowing us to test CURRENTANSILINE and determine if we need to blow it up, or save it.

Line 92 tests CURRENTANSILINE against the Planet Class the user selected. This is also an example of how scripts generally detect a Spoof attempt (Remember, $Lines[$ii][1] contains ANSI Codes that we're using to match against planet just created.)

Let's assume that the planet just created is not what we're looking for we need to give it a unique name to ensure the right planet is blown-up.

Line 94, obtains a Random Number to be appended. Line 95 is a tad superfluous, but brings it all together and Line 96 sends the Junk Planet Name. When creating and blowing up planets in an automated fashion, it's better to be safe and make sure that the planet you're about to blow-up is in fact the correct planet. Utilizing a random number assists in preventing any accident by ensuring the you obtain the correct Planet-Number from the Registry List.

Line 102, will allow us to catch Planet designation: Corporate, or Personal. Later on, this can be added as a customizable feature.. if you're on a Corp, you might want to make some planets Personal to minimize TL Spam (Corp Planet Listing).




As you can see, using a String-matching routine to determine which planet we just popped is pretty simple. Line 113 tests the Variable $PlanetLabel to determine the next step. Lines 114 through 139, kill a lot of birds with one stone.

First thing, "L" is sent to the server and the code waits for one of two possibilities: Landed right away, or a Planet-List is about to be drawn (indicating either a planet scanner, or multiple planets exist).

If all goes well, Line 138 jumps back up to Line 70, and the process repeats until desired planet materializes, you run out of Atomics/GenTorps, or you Pod because you didn't have enough Fighters/shields.

Remember that the above code is Bare Bones; there should be a lot of checking included to make it safer (i.e.: Warning User about Self-Torping if their ship contains Photons, Turns are too low, Experience gain limiter, etc ,etc.


End Note:

I use Context (, and my own Syntax HighLighter which you can obtain Here. Also the Text file of the code represented above, Here.


-/- FIRST PAGE -/-