Planet Creation Article
-/- PAGE 1 -/-


I started on a new script that required some original routines to accomplish an objective. One of the objectives involves creating a specific planet class. I thought querying a user for a planet class would make for an excellent basis upon which to illustrate some Scripting Techniques that I've learned by way of study, and created out of necessity. Please bare in mind that Programming, in general, is inherently malleable such that one single task can be achieved in a myriad of ways. Reading between the lines, you can guarantee that there's probably a better way of doing many, if not all, of the objectives I'm about to cover :)

The end result of this article will be a simple script that mirrors almost exactly Alexio's Planet Creation Script. As an exercise, one could improve upon a couple short comings in Alexio's script; to name a couple: Wont Overload a Sector; In order to Furb in a Sector w/o a Port you need to set it to Furb from a planet with a bogus Planet Number. 

Also pictured to the right are two routines that I created from scratch just to show that there's no single Right way of coding; there's definitely a wrong way.

Creating a planet. A very simple process, from the Command Prompt type: U Y My Planet* C  ..and you get a Corp planet called 'My Planet' ... a Macro will Achieve same: U Y My Planet* C  ... exactly the same thing except it can be repeated 100's of times in no time flat. However, several conditions can arise that will possibly send you off into oblivion. So, one possible Macro that might cover all the bases and not get you #SD# could be: 

U Y N  .* J  C * the risk of digressing, that little snippet just about covers every eventuality --even some yahoo completing a Planet Buyout during a long macro cycle. It's a great Macro. But what if you're looking for a certain Planet Class?  A Macro doesn't know, doesn't care about what just materialized, it'll burn through whatever number of cycles you've designated; and then you'd still have to go back and search for what you're looking for. This is where the power of Scripting enters the picture. 


Question: How to get Planet-Classes into a Script Menu for user selection, irrespective of the Game Edit?  


A)  Ask the User to type the name of the planet class exactly. 

B)  Have the user manually create a Text File with Planet Class data to be culled and outputted to a menu.

C)  Query the user at every planet created: Is this what you're looking for (Y/N)?

D)  None of the above



Answer is D, None of the above.

What I'm going to show you entails scanning the Planet Catalog, present a Menu containing that information and then bust planets until that planet is created or you run out of Genesis Torpedoes, or Atomic Detonators. 


Click Here for Script Listing to follow along with Line Number references. The text file; here.


As the image illustrates. Pressing this key sequence: CJ?QQ  from the Command Prompt will display the Planet Types in any game edit. 

Line 32, does just that:  send "CJ?QQ" the fun is capturing the information sent by the Server. Lines 33 through 51 do just that. You see, the trick to using Triggers involves sending a burst of characters and then immediately setting the Triggers that will grab exactly what you're looking for. In this case we're using two TextLineTriggers (Lines 34, and 36): 

Respectively: Detect when the burst "CJ?QQ" of Text is finished (line 34), and analyze every line sent by the Server (Line 36). As you can see there are a lot of lines involved in the simple string: CJ?QQ, so to improve performance a bit we tell TWX to wait and hold on until the last possible Line, and *then* start working with the Triggers, Line 33 achieves this.

Once Line 33 is satisfied, Triggers are then set and TWX Pauses (Line 37). This is where LineTrig starts to work. The very next line of text sent by the Server following the waitfor condition ("Which planet type are you interested in" Line 33), is a blank/empty line. 

Line 41 tests for an empty/blank line sent from the Server and disregards it, returns to Line 35 and processes the next line of text sent from the server. It just so happens the very next line is a planet class.

Lines 41 through 50 filter out any and all unintentional text by using CURRENTANSILINE. At this exact moment in time the CURRENTANSILINE variable contain this exact string of Text:


Referencing the above Planet-List image, you should be able to work out where in the above ANSI string the information we're searching for is 'embedded'.  

Note: the small square (aka Control Character: Escape Sequence, will be referred to here on, as it's TWX equivalent #27)

Since we're looking for Earth Type and it's associative Menu Letter: A. The goal here is to filter out the data from CURRENTANSILINE and use it later as contextually as possible. In this case we're in luck. Just before the text: #27 & "[33mEarth ..." is "  " & #27 & "[0m" the script Line 43, replaces that with a known "^^" and then Line 44 appends "@@" to the end to better assist with the extraction of the Planet Class Name.  

Line 45 removes exactly what we're looking for and more. Unlike Alexio's script, we're going to present the User with a selection of planets in the same glorious ANSI colour found in the original Menu. Admittedly, it's a small 'enhancement' but a nice one, none the less (I'd wager CURRENTANSILINE wasn't available when Alex wrote his Planet Creation script).

Line 46 Extracts the associative Menu Letter (in this case the letter A), for later use.

Lines 47 and 48, as a precaution strip any errant Carriage-Return and Line-Feed that might make it's way into the outputted Menu and reek havock later on.

Lines 45 and 46 also store the information into a Static Array (an array with preset elements), we could use a Dynamic Array (elements that can grow/added-to as needed), it's a preference thing. I'll explain the Array shortly.

Line 51. Once all the above has been hashed out, the routine loops back up to Line 35 and the process repeats until the text sent from the Server triggers the TextTrigger at Line 34: 

setTextLineTrigger Done :Done "<Q> To Leave"

Once the above text is sent by the Server All-Triggers are stopped (Line 53), and execution moves onto getting the user input (Lines 55 through 68). But before we delve into the Menu, let's cover the Array I've implemented in the next section...

-/- NEXT PAGE -/-