Understaning Torque Game Engine
by Alexander Schunk · 07/15/2004 (8:43 pm) · 4 comments
Understanding Torque
All the main game functionality is implemented within the scripts shipped with the Torque engine. However, you wont gain much success if you dont understand how Torque calls scripts and how scripts call other scripts etc.
The Torque sample game folder structure
A basic concept of Torque is the folder and file structure. Each sample game has at least 2 folders: CLIENT and SERVER and DATA. It also has a main.cs file that starts it all.
The main.cs file is stored separatly and not in one of the folders mentioned above. This file calls the engines start and exit routines and some other cleaning up code.
The lines of code below show for example the parseArgs function that parses the command args of the Game Engines main.cs. You know the main.cs file where you can switch between the different games starter.fps, fps etc.
Client and Server
The Client and Server folders have both the same structure except that Client also has an ui folder that contains scripts of the main GUI layout.
The folder both have in common in the scripts folder which holds the scripts that implement the core functionality of client and server.
The Data folder usually holds such things like textures, sounds, bitmaps etc. and is not of further importance to us.
Respecting this basic folder structure is of importance because the main.cs file that starts the sample app assumes that this very structure exist untill you have not changed the $modpath or the $baseMod and $userMod variables within the main.cs.
Core sample app files
After this short introduction into folder sturctures and their importance i will now explain some other important script files.
config.cs //holds default Key bindings like ESC, ~ etc.
canvas.cs //implements the main screen functionality
default.cs //contains basic game settings in Client
init.cs[/] //implements basic initialization
[i]prefs.cs //contains basic game settings: in Client
Please note that there may be more than one file with the same name, i.g. Client/init.cs and Server/init.cs. Also, there may be multiple main.cs files, i.g. Client/main.cs, Server/main.cs etc.
All these files are of highest importance for the Game Engine and for the Game itself. I will discuss each of it and its task thoroughly now.
1. init.cs
As its names says, init.cs implements basic initializations by calling the exec("") function.
2. canvas.cs
Again, this file speaks for itself, canvas.cs simply implements tha main screen GUI and executes the other gui files.
3. default.cs
This file is a bit more tricky. It actually holds basic game settings like videomode on off, sky on off, playermode, number of players, etc. In fact, it changes the default behaviour of the sample game. You may play around with the many settings of this file to get more accustomed to it and get more inside knowledge how the Torque engine works.
4. prefs.cs
This file also holds default game settings and also has many options to play with. Note that both default.cs and prefs.cs are stored in the Client folder. There Server folder has these files too, yet with less options to choose.
Playing around with the last 2 files will help you learning more about the Torque Game engine and its features.
All the main game functionality is implemented within the scripts shipped with the Torque engine. However, you wont gain much success if you dont understand how Torque calls scripts and how scripts call other scripts etc.
The Torque sample game folder structure
A basic concept of Torque is the folder and file structure. Each sample game has at least 2 folders: CLIENT and SERVER and DATA. It also has a main.cs file that starts it all.
The main.cs file is stored separatly and not in one of the folders mentioned above. This file calls the engines start and exit routines and some other cleaning up code.
The lines of code below show for example the parseArgs function that parses the command args of the Game Engines main.cs. You know the main.cs file where you can switch between the different games starter.fps, fps etc.
//exec() function calls
function parseArgs()
{
Parent::parseArgs();
// Arguments, which override everything else.
for (%i = 1; %i < $Game::argc ; %i++)
{
%arg = $Game::argv[%i];
%nextArg = $Game::argv[%i+1];
%hasNextArg = $Game::argc - %i > 1;
switch$ (%arg)
{
//--------------------
case "-dedicated":
$Server::Dedicated = true;
enableWinConsole(true);
$argUsed[%i]++;
//--------------------
case "-mission":
$argUsed[%i]++;
if (%hasNextArg) {
$missionArg = %nextArg;
$argUsed[%i+1]++;
%i++;
}
else
error("Error: Missing Command Line argument. Usage: -mission <filename>");
//--------------------
case "-connect":
$argUsed[%i]++;
if (%hasNextArg) {
$JoinGameAddress = %nextArg;
$argUsed[%i+1]++;
%i++;
}
else
error("Error: Missing Command Line argument. Usage: -connect <ip_address>");
}
}
}
//the onStart() and onExit() functionClient and Server
The Client and Server folders have both the same structure except that Client also has an ui folder that contains scripts of the main GUI layout.
The folder both have in common in the scripts folder which holds the scripts that implement the core functionality of client and server.
The Data folder usually holds such things like textures, sounds, bitmaps etc. and is not of further importance to us.
Respecting this basic folder structure is of importance because the main.cs file that starts the sample app assumes that this very structure exist untill you have not changed the $modpath or the $baseMod and $userMod variables within the main.cs.
Core sample app files
After this short introduction into folder sturctures and their importance i will now explain some other important script files.
config.cs //holds default Key bindings like ESC, ~ etc.
canvas.cs //implements the main screen functionality
default.cs //contains basic game settings in Client
init.cs[/] //implements basic initialization
[i]prefs.cs //contains basic game settings: in Client
Please note that there may be more than one file with the same name, i.g. Client/init.cs and Server/init.cs. Also, there may be multiple main.cs files, i.g. Client/main.cs, Server/main.cs etc.
All these files are of highest importance for the Game Engine and for the Game itself. I will discuss each of it and its task thoroughly now.
1. init.cs
As its names says, init.cs implements basic initializations by calling the exec("") function.
2. canvas.cs
Again, this file speaks for itself, canvas.cs simply implements tha main screen GUI and executes the other gui files.
3. default.cs
This file is a bit more tricky. It actually holds basic game settings like videomode on off, sky on off, playermode, number of players, etc. In fact, it changes the default behaviour of the sample game. You may play around with the many settings of this file to get more accustomed to it and get more inside knowledge how the Torque engine works.
4. prefs.cs
This file also holds default game settings and also has many options to play with. Note that both default.cs and prefs.cs are stored in the Client folder. There Server folder has these files too, yet with less options to choose.
Playing around with the last 2 files will help you learning more about the Torque Game engine and its features.

Alexander Schunk
In the 2nd paragraph, it is 3 folders of course, not 2.
i apologize for the many typos in this text ;).