Torque Game Builder Tricks

So I’ve decided to put together a few small tricks I use when I make games with GarageGames’ Torque Game Builder (or TGB as I call it).

Scheduled Events

This is a function call that allows you to call another function at a specific time in the future. For example, you could use this to play music 2 seconds into the level instead of right away. To do this, you could have your audio call in a global function like this:

function PlayLevel1Music()
alxPlay( Level1 );

Then you would schedule it from a block of code that would get executed on level load (such as a scene object).

schedule( “”, 2000, “PlayLevel1Music” );

One other interesting use of the schedule function is to have a function schedule itself. This acts as what Visual Studio calls a timer. Here is an example of an energy recharge gauge for the player. It will call itself every second and use “addToGauge” to actually add to the energy.

function playerClass::recharge( %this )
%this.rechargeTimer = %this.schedule( 1000, “recharge” );

Notice I assigned the schedule to the player’s rechargeTimer variable. This is not necessary, however doing this allows you to cancel the function call like this:

Cancel( %this.rechargeTimer );

An example of how this could be useful is if the player can only recharge while standing on a recharge station. If the player leaves the station, you would cancel the recharge call.


Programmers that have used other languages will notice right away that TorqueScript has no arrays. However, there exists a container object that can generally be used in it’s place.
Creating a SimSet is easy:

%container = new SimSet();

Say you want the player’s class to contain a premade list of particle effects for spells. You would add them to this list like so:

%container.Add( %spellEffect1 );

If you want to retrieve the stored spell, you can address it by index like this (keep in mind, the first index is zero):

%spellEffect = %container.GetObject( 0 );


Sometimes you will come across data in TGB that is space separated. For example, when you call a scene object’s GetPosition function, you will get something like this: “0 50”. Yes, you could just use GetPositionX, but in general if you want to separate this data here is how. Say you want to get the first value in variable %position, do this:

%PosX = GetWord( %position, 0 );

This will grab the first value as long as it is separated by a space character.
An example of how this can be useful will build on the example from the SimSet section. Say you want to also store the names of the spells with their particle effects.
To store them, you would do this:

%container.add( “Fire” SPC %spellEffect1 );

When you go to retrieve the data, you will need to use the GetWord function like this:

// Get the spell entry
%spell = %container.GetObject( 0 );

// Get the spell name
%name = GetWord( %spell, 0 );

// Get the particle effect
%effect = GetWord( %spell, 1 );

You can then use the %name and %effect variables however you want.

Separate Datablock Files

This is a small trick, but it can really help you organize your datablock files if you are making a large game. You can call other datablock files from your primary one like this (the one TGB gives you when you start a new project):

exec( “./datablocks_enemies.cs” );

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: