Game Development Community

Torque script 101

by Taslim Dosunmu · in Torque Game Engine · 06/27/2007 (9:24 pm) · 3 replies

This post is being parked for infinitum3d

#1
06/28/2007 (6:19 am)
You've seen his other topic, I assume. Next, go through TDN and learn a little bit more about the engine you purchased.
#2
06/29/2007 (8:19 am)
Thank you
#3
07/02/2007 (10:17 am)
Taslim requested a graph of "how to place files in folders and in main directories", as well as an explanation of main.cs

I'm not a programmer, so if anyone can help with explaining Main.cs we'd all appreciate it. I'll look in the TDN and other forums and see what I can find.

According to Adam Baratz www.garagegames.com/mg/forums/result.thread.php?qt=2380
Quote:

The main.cs script is in charge of loading the mods specified in the $baseMods and $userMods variables declared at the top, along with processing command-line arguments. It loads the mods by executing their main.cs scripts. The few weirdo functions in the main main.cs script are for parsing the mod strings. The only kinda complicated one is popFront(), but it's pretty clear if you check the function it calls, nextToken() (it's in engine/console/consolefunctions.cc). Tip: if you need help understanding a function call, add in some Con::printf("debug output here") statements to the C++ code. They're regular printfs, except they're output to the console (the printf function of the console object). Very handy for seeing how stuff works.

The functions in main.cs are called like they should be. The code reads straight through, only calling them when specified. Sandwiching functions between regular code wasn't the wisest way to coherently code it, but that's what they did. A lot of the functions you see are generic functions that are just left for other mods to fill in. This is where the package system comes into play. Packages let you group a bunch of functions together so they can override each other depending on the circumstances. For example, you might have a lot of general script, but some of it needs to be changed for a certain game type. You activate that package (activatePackage(newPackage);), and then those functions are called instead. You can see a quick example of this in main.cs, lines 152-171. That onExit() function is only called when the Help package is activated, and it's activated when the help is displayed. Think of it like grouping virtual functions together.


Also, according to Craig Courtney www.garagegames.com/mg/forums/result.thread.php?qt=35838

Quote:
Torque is structured to allow add-ons which makes the default directory structure somewhat difficult to grasp at first. The source directories are also somewhat confusing at first glance. The "demo" that you compiled is your engine and you can change the name of the executable via project settings in your compiler. The example folder where your demo is placed is the root folder of your game, anything in this folder and it's sub-folders is what you would package to distribute your game (minus any debug dlls). The engine when starting bootstraps by loading main.cs and executing it, this script has the job of setting up the path for script and data loads (or the "mods") and starting execution of your game by starting the scripts. Each of the subdirectories in the example folder are "mods" these mods contain code and game shapes, graphics, sounds and music. The "common" mod contains generic basic game functionality and contains the bulk of the torque script API and the editors. It is not strictly required for your game. The other folders contain tutorial or starter games which can be thought of as templates to get your game kick-started.

To start from a blank page all you need is your executable engine and a blank main.cs file. It's up to you how you structure your directories and how the game execution kicks off with main.cs. You will likely want to use at least the common mod from the example directory so you can use the in game editors to create your missions.

Also, the beginner tutorial "gettingstarted.pdf" tdn.garagegames.com/wiki/Beginner/Torque_Intro explains directory structure a little.

Here's the basics:

1. The root of your game data is defined by where the Torque executable is. In the example folder, that executable is called torqueDemo.

2. In the same folder as torqueDemo, there will be a script file called main.cs, which is the first thing that the Torque engine looks for when the executable is run.

3. If you look near the top of the main.cs file there's a line that says '$defaultGame = "tutorial.base";'. That line tells the Torque engine where to look for the rest of our game files. By default, it the folder called tutprial.base

4. In the tutorial.base folder you'll see some more scripts and a few folders. Basically the scripts in this folder contain more start up info for our tutorial game, the client and server folders contain the meat of our game scripts, and the data folder contains all our resources, like models, textures, sounds, and a few scripts that deal directly with those resources.

After running Torque for the first time, you'll also notice that for every .cs file there is a corresponding .dso file. The .dso files are compiled versions of the .cs script files. The engine will automatically recompile your scripts if your .cs file has changed since the last run.

Now I know this is very basic. Hopefully someone better educated in Torquescript can explain why certain files go in specific locations. i know that things needed by the server go in the server folder, but how do we know what is needed by the server and what is simply needed by the client?

Thanks! I hope this helps.
Tony
not a programmer