Game Development Community

dev|Pro Game Development Curriculum

A Basic console

by Johnathon · 11/07/2007 (4:36 pm) · 3 comments

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.

#1
11/07/2007 (5:02 pm)
For a moment there I was thinking you'd made a BASIC interpreter inside the console in Torque... :)
#2
11/07/2007 (5:39 pm)
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.