Starsiege Scripting Tutorial: The Console and Debugging
by Orogogus


Activating the Console

The console is one of the most powerful tools at your disposal for troubleshooting. To activate the console, start the mission editor and press the tilde (~) key. From here, you can type commands directly into the server, and see certain server messages as well. Press the tilde again to hide the console again.

Side note: you can enable the console even when you're not in the mission editor. To do this, open the autoexec.cs file in your Starsiege/scripts folder, and change

if ($me::enableMissionEditor) 
   Console::enable(true);
to

// if ($me::enableMissionEditor) 
   Console::enable(true);
Another way to access the console is to start a dedicated server. The DOS box that results is a permanent console window.

One last console entry point is through telnet. If you set up a dedicated server, you can include the following two lines:

$TelnetPort = 29001;
$TelnetPassword = "password"; 
Then, whenever the server starts, you can telnet into the IP address of your computer, using 29001 (or whatever you entered) as the port. Enter the password, and you'll be in a console window.


But What Can I Do With It?

From the console, you can type in statements and functions exactly as in your script. One useful function that applies primarily to the console window is echo(). If you type echo("Text"); into the console, the word Text will appear on the console screen, but not in the game. This is often used to check on variables in a script, to see if they're behaving the way you expect them to.

Note that you can use Page Up and Page Down to scroll through the past contents of the console window.

Another console-oriented functions are playerList(), which tells you all the players in a server along with their playerIDs, as well as their team, kills, deaths and pings. ListObjects() is a good one, too, although it's hard making head or tail of which objects do and don't show up on the list. Two more are focusclient(); and focusserver();. Without going into detail, it's important to know that a client and a server have their own object lists. There are a lot of objects that a server can see but the clients can't, and a few that work the other way, too. Also, the objectIDs don't line up, either, and clients are forbidden from running a lot of functions like damageObject() or setPosition(), so be sure to run focusserver() if you're going to mess around much with the objectIds on a server. Run focusClient() mostly if you're going to play with the HUD, or if you need keys like ESC to start working again. If you're in a dedicated server window, or telnet into a server, you're automatically in focusServer() mode.


The console and debugging

Probably the single most useful aspect of the console, from a scripting standpoint, is the ability to catch syntax errors. When testing a script, the first thing you should do after loading the mission (before you even join the map) is open up the console window. If your script has an error in it, then you should see something like

**************************Line: 432 - SYNTAX ERROR

This pops up for any kind of error like missing semicolons, two equals signs when you really want one, one equals sign when you want two, problems with quotation marks, and so on. Make sure you're using a text editor that can tell you the line number (not Notepad or Wordpad), because it makes debugging much, much easier if you can jump directly to the problem areas. If you can't see anything obviously wrong, look through the lines immediately preceding the given line number as well. A missing semicolon at the end of line 431 will create an error in 432. If you're absolutely, positively sure that there's nothing wrong in these two lines, then it's probably time to start counting curly brackets, and see if there's one missing or one too many.














1