Previous Blog Next Blog
Prev/Next Blog
by date

A Basic console

A Basic console
Name:Johnathon 
Date Posted:Nov 08, 2007
Rating:4.0 out of 5
Public:YES
Comments:YES
RSS Feed:GarageGames Blog feedor Subscribe with .
Profile Page:View profile page for Johnathon

Blog post
Well I was actually pretty surprised at how quick I was able to get a blank slate ready with the Torque Script. I thought I would share what code I had wrote to get it up and running.

root main.cs file

//Enable detailed logging
trace(true);

//Force the console to be displayed since we don't have a canvas yet.
enableWinConsole(true);

$gameName = "MyGame";

// Help won't be displayed unless the command line
// switch (-h) is used.
$showHelp = false;

$logModeEnabled = true; //Track the logging state we set in the lext line.
SetLogMode(2); //Create a new log file

//Any last gasp exit code we want executed can be performed here.
function OnExit()
{
}

function OnStart()
{
}

function ParseArgs()
{
//Loop through all the command line arguments.
for ($i = 1; $i < $Game::argc; $i++)
{
$currentarg = $Game::argv[$i];
$nextArgument = $Game::argc[$i+1];
$nextArgExists = $Game::argc-$i > 1; //returns true if there is another argument in the list.

switch$($currentarg)
{
case "-?":
$showHelp = true;
$argumentFlag[$i] = true;
case "-h":
$showHelp = true;
$argumentFlag[$i] = true;
}
}
}

function ShowHelp()
{
echo("\n\n"@ $gameName @ " command line options:\n\n -h, -?\ndisplay this message.\n");
}

ParseArgs();

// If we are wanting to show the help, enable the console
// display the help message, disable the console and exit.
if ($showHelp)
{
enableWinConsole(true); //Send logging output to a Windows console window
ShowHelp();
enableWinConsole(false);
quit();
}
else
{
for ($i = 1; $i < $gameName::argc; $i++)
{
if (!$argumentFlag[$i])
error("ERROR: Unknown command line argument: " @ $gameName::argv[$i]);
}

if (!$logModeEnabled)
setLogMode(2);

echo("Engine Initialization completed.");

exec("Base/Init.cs");
OnStart();
}


Base/Init.cs file

package Base
{
function OnStart()
{
Parent::OnStart();
echo("------ Initializing Base ------");
}

function OnExit()
{
Parent::OnExit();
}
};
activatePackage(Base);


now I can start coding away, learning the ins and outs of TorqueScript by writing little functions and testing them with the console. Once I get to the point where I will need 3D, I will start work on a canvas.

Recent Blog Posts
List:01/07/08 - Airhead Gaming goes live
12/08/07 - Airhead Gaming
11/29/07 - Solitaire *Work in progress*
11/18/07 - New direction
11/16/07 - Mission Load Stage 2 endless loop
11/11/07 - Simple backup script
11/08/07 - Creating a canvas
11/08/07 - A Basic console

Submit ResourceSubmit your own resources!

Jay Barnson   (Nov 08, 2007 at 01:02 GMT)
For a moment there I was thinking you'd made a BASIC interpreter inside the console in Torque... :)

Jeremy Jenkins   (Nov 08, 2007 at 01:39 GMT)
Pretty cool, it would be nice if you continued to post your progess. Seeing the steps in creating a game from scratch would make for a very good read.

James Brad Barnette   (Nov 08, 2007 at 19:08 GMT)   Resource Rating: 5
amen

You must be a member and be logged in to either append comments or rate this resource.