User Login
Name
Password
Site Contents
News
About
Download
Scripts
Tutorials
Register
Support
FAQ
Script Reference
New User


Contact Me
Xide
Tutorials
TWX Scripting Guide, Part 1 - Basic Scripting
Author: Xide Updated: 8/12/2001

Scripting within TWX is actually very easy to learn. You don't need to be a hotshot programmer, infact you don't even need any previous scripting knowledge at all (although this does help). All you need is a purpose, a reference, knowledge of a text editor and a logical way of thinking.

TWX scripts are basically text files. Any file with the .ts extension is a 'Tradewars Script' file, and can be opened in any text editor (including notepad, dosedit, etc). The scripts are built up of a sequence of commands, conditions and pauses which control data that TWX sends to the TWGS server. I'll start by explaining the format for the scripting commands, then going through some simple commands in a very basic TWX script and explaining what they do.

Here is the script I'll be explaining. Below is a basic login script for a standard TWGS server.


send "Xide*"
waitfor "Trade Wars 2002 Game Server"
send "a"
setVar $wait "module now loading."
waitfor $wait
send "*t***mypassword***"
waitFor "Command [TL="


If this script is run from the 'Please enter your name' prompt when you first connect to a TWGS server, it'll attempt to log you in using the above username and password. Now, onto the commands...

send "Xide*"

The send command is used to send commands/data to the tradewars server. Note that the text being sent is enclosed in quotations ("Xide*"). Any text that is enclosed in quotations will be sent exactly as you've typed it, and the * character gets converted to the enter key. This is also the only way you can send a space. What this command will do is send the user name to the login prompt of the TWGS server, then press enter.

waitfor "Trade Wars 2002 Game Server"

The waitfor command will pause the script until certain text is received from the tradewars server. In this case, the script will stop and wait until it sees the text "Trade Wars 2002 Game Server". As soon as this text shows up, the script continues with the next command.

send "a"

As before, this command sends the text "a" to the server. In this case its sending the game letter of the game we're logging into.

setVar $wait "module now loading."

The setVar command sets a variable. In this case, we're setting the variable $wait to the text "module now loading.". Although in a script such as this variables have very little use, they are an essential part of more complex scripts (explained later).

waitfor $wait

Here we have our first variable reference. Although this wasn't really necessary, I wanted to show how variables could be used. In this case, we're waiting for the text thats stored in the $wait variable that we set earlier. You could argue this command is exactly the same as: waitFor "module now loading."

send "*t***mypassword***"

If your able to follow what this command sends, you can see that it fires off the password and completes the whole login process. Note the extensive use of the enter key (*) in this command.

waitFor "Command [TL="

We conclude our script with a waitFor command that will wait until we hit the command prompt in our game. Technically, this command isn't really needed. But its often good practice to confirm if the login was completed or not.

As soon as TWX hits the bottom of the script, the script is automatically terminated. You can terminate a script at any time by using the 'halt' command.


Return to Tutorials Page