Game Development Community

Console Questions

by Michael Dawson · in Torque Game Builder · 03/03/2009 (5:56 pm) · 5 replies

Hello. I may be working with students and TGB. I want to introduce scripting via the console so that students can see the immediate impact of a single programming statement, but I have a couple questions about the TGB console.

1. I'd like to make the console text larger so it's more readable. Is it possible to increase the font size of text in the console? Or is it possible to use some type of editor for console input/output where I can control the font size (like maybe with Torsion)?


2. Is it possible to enter multi-line blocks of code in the console? I've tried to enter a multi-line if statement, like:

if (true)
{
    echo("This will always be displayed.");
}

But I can't enter more than one line; as soon as I hit Enter, the preceding code is evaluated. Is there some type of line continuation character perhaps? (I can, of course, enter the whole if statement in one line, but I'd like to use multiple lines for clarity)


3. Is it possible to run a script from the console? I've tried and I always get an error message saying that the script file I want to run can't be found. For example, if I enter the following at the console:

exec("test.cs");

I get back the message:

Missing file: C:/Program Files/GarageGames/TorqueGameBuilder-1.7.4/games/Interact/test.cs!

even though I have a file named test.cs in that very directory.

Thanks for any help,

--Mike

#1
03/03/2009 (7:03 pm)
1. You can change the font size by changing the GuiProfile properties. The Console control uses the profile "GuiConsoleProfile" found in "<ProjectDir>/common/gui/profiles.cs". Find this line in the declaration:

fontSize = ($platform $= "macos") ? 13 : 12;

Change the resulting value to the appropriate size.

2. You can't do it without giving the console itself some special treatment. In the "<ProjectDir>/common/gui/console.gui" file, you can see the reference to a "GuiConsoleEditCtrl" object called "ConsoleEntry".

Theoretically, you could replace this with a "GuiMLTextEditCtrl" control and tweak the "ConsoleEntry::eval()" function to suit. I've not done this myself, but it is definitely "doable".

3. You should be able to exec() files from the console. Did you run that while running the game, or while you were in the editor? I don't see a problem with what you did.
#2
03/03/2009 (8:16 pm)
Philip -- Wow, thanks for the quickly and thorough reply.

1. That did the trick. I'm able to change the console output an input font sizes with that idea.

2. Thanks for the tips, I'll look into seeing if I can make the changes.

3. I entered exec("test.cs"); in the console while the game was running. Basically, I want to be able to run a script that changes the game on the fly.

#3
03/03/2009 (10:14 pm)
Just a quick question, what is contained within "test.cs"? If the file is empty, then it will throw out an error saying that it is an invalid script file. I just tried a test script file throwing out an echo command and it ran properly.
#4
03/04/2009 (8:28 am)
2. you can do it if you make it all one line, but it's not very appealing. eg if (true) { stuff(); }

3. i make heavy use of manually reloading script files from the console,
so much of my development cycle is:
* edit foo.cs in the editor of my choice
* in the console, reload the script (more on that below)
* in the console, re-execute some function defined in foo.cs

to reload scripts, i make a function called, imaginatively, reloadScripts(). i prefer this to typing out the exec() line because i can use tab completion on function names but not on file names.

re the core exec() call, i believe there is a trick where the engine will only look for files in paths which have been declared. try exec("./test.cs"), and if that doesn't work, try putting the file inside a subfolder which already contains script (other than main.cs), and then exec()ing it in there. eg exec("folder/test.cs"); - i'm not familiar w/ the TGB folder setup or i could recommend one in particular.

in actual development, my reloadScripts() routine reloads almost every script in the game. if you design your scripts with this in mind, this is a huge time-saver over constantly restarting the app.
#5
03/04/2009 (10:35 am)
Moving the script file to a subfolder worked. I was able to run it by putting the file in the games folder and then entering exec("games/test.cs"); into the console. Odd that I can't execute a script located in the root project folder -- but this will work. Thanks Phillip and Orion!