Tuesday, August 26, 2008

Setting up Torque

Before we go any farther, it would be nice to be able to test our modules and functions to make sure they do what we think they do. If you haven't yet, go ahead and download the latest version of the Torque Game Engine (TGE) from Garage Games:


Download TGE HERE


One you have installed TGE you should have a folder named TGE_1_5_2 or something similar. Unless you know C++ already, you are going to have a ton of extra files that you won't really have a use for right now. The folder we are most interested in is under that one TGE_1_5_2\Example\

Under that folder go ahead and create a directory called "Test". This is where we will put all of our modules before we try them out.

Now, go ahead and double-click torqueDemo.exe. This will start Torque and allow us to test our modules. Once Torque is open, open the console window by hitting the "~" key. The "~" is your friend. Trust me.

Ok, so lets make something to test. Open notepad.exe or another text editor and create a new document. Then, type in the following module. You will need to save it as type "all files" or "*.*" and name it takedamage.cs and save it to the TGE_1_5_2\Example\Test folder you just created.

Since yesterdays module covered a lot of territory, lets go ahead and use it as our example:

//takedamage.cs
//reduces health after being hit or falling

function healthtracker()//main function doesn't need an arguement
{
%playerHP = 100; //initializes player health at 100

echo ("Starting Player HP ="@%playerHP); //prints the players current health to the console

%playerHP = take10dmg (%playerHP); //calls the function "take10dmg" and passes the players current health as an argument
echo("Player HP after fall ="@%playerHP);//current health to console

%playerHP = take10dmg (%playerHP); //calls the function "take10dmg" and passes the players current health as an argument
echo("Player HP after hit ="@%playerHP);//current health to console
}

function take10dmg (%playerHP) //create the new function. Can use the same variable since it is local
{
%playerHP = %playerHP-10; //reduce HP by the stated amount
return %playerHP; //passes the arguement back to the calling function
}

Once you have it typed in (or cut and paste) and saved as takedamage.cs open the console window in Torque and type in: exec("/test/takedamage.cs");

Make sure to use "/" and not "\" inside of Torque.

Once you type that, Torque will load and compile your module. If you make any changes you will need to reload the module before Torque sees the changes you have made.

Next type: healthtracker

And the function should run and you should see what happens to %playerHP when they take damage.

No comments: