Game Development Community

Question about paths (and *.tgb files)

by Jesse Chounard · in Torque Game Builder · 05/02/2006 (12:45 pm) · 5 replies

I'm a total beginner when it comes to TGB, so I'm sorry if any of my questions are silly, or easily found in the documention. (I did alot of searching before posting here, though there's alot to read so I could have overlooked it.)

In the level builder, I've created a new project, called Test01, and a level called TestLevel1.t2d, which I saved in my Test01/data/levels folder. When I run in the level builder, everything comes up exactly how I'd expect. When I run from Torsion (with "-notools -game Test01" as options) I get the following error:

"Error loading level ~/data/levels/baseLevel.tgb. Invalid file."

I've done a full Windows file search, and I cannot find any *.tgb files anywhere.

1) Why don't I get that error when I run from inside the level builder?
2) What does the tilde at the start of that path mean?

So, since I couldn't find any *.tgb files on my machine, I tried putting in the path to the level I'd built. But none of the following worked:

sceneWindow2D.loadLevel("~/data/levels/TestLevel1.t2d");
sceneWindow2D.loadLevel("./data/levels/TestLevel1.t2d");
sceneWindow2D.loadLevel("Test01/data/levels/TestLevel1.t2d");

However, the following two did work:

sceneWindow2D.loadLevel("C:/tgb/latest/games/Test01/data/levels/TestLevel1.t2d");
sceneWindow2D.loadLevel("~/../Test01/data/levels/TestLevel1.t2d");

3) What's the "current" directory, where I start from in creating relative paths?

Since I've gotten it to work, I can move on to learning different parts of tgb, but I don't like not understanding what's going on here. Thanks in advance for any light you can shed on this for me.

#1
05/02/2006 (1:41 pm)
1. You dont get that error inside the level builder because:
function initializeProject()
{
   // Load up the in game gui.
   exec("~/gui/mainScreen.gui");
   
   // Exec game scripts.
   exec("./gameScripts/game.cs");
   
   // Remove the following four lines if you would like to start the game without running the
   // level builder.
   if ($runWithEditors)
   {
      toggleLevelEditor();
      return;
   }
   
   // This is where the game starts. Right now, we are just starting the first level. You will
   // want to expand this to load up a splash screen followed by a main menu depending on the
   // specific needs of your game. Most likely, a menu button will start the actual game, which
   // is where startGame should be called from.
   startGame("~/data/levels/baseLevel.tgb");
}
In here, when you run with the level builder, it calls toggleLevelEditor() then returns out of the function. It's as if that startGame function at the bottom there never existed. Instead startGame(%level) gets called with you press the play button in the level builder. %level being the current level you have open in the builder. Only with $runWithEditors set to false would that particular startGame run.
#2
05/02/2006 (1:59 pm)
Thanks, Mike. That seems really obvious in hindsight. I'd assumed that runWithEditors was false when you hit start, since it didn't show the level builder anymore. Silly me. :)

Is the .tgb file there a remnant from an earlier beta, and .t2d the way to go now?

If I can just figure out how the relative paths work, I think I'll be good to go.
#3
05/02/2006 (2:09 pm)
For 2. and 3. - paths can be a bit confusing (to me too). The ./ file path is from the current working directory. So if I added exec(./player.cs); inside of game.cs (which is in the gameScripts folder), TGB would look for the player.cs file inside the gameScripts folder.

The ~ is where things get fun. For a chuckle, even from the script above there are 2 different syntaxes:
// Load up the in game gui.
   exec("~/gui/mainScreen.gui");
   
   // Exec game scripts.
   exec("./gameScripts/game.cs");
Both work. The ./ for game.cs is ok, because the current file (main.cs) we are looking at is by default in T2D or the folder you named from starting a new project. So it finds the game.cs file in T2D/gameScripts, for example.

The ~ is where it falls apart. ~ means from the exe root path. If my exe is in the games folder (from an unmodified .zip extraction of the SDK), I am also a bit confused why exec("~/gui/mainScreen.gui"); is ok, but startGame("~/data/levels/baseLevel.t2d"); would give me an error. Instead I had to use startGame("T2D/data/levels/baseLevel.t2d"); for the "baseLevel" to load ($runWithEditors set to false).

Hopefully this can get cleared up for both of us. ;)
#4
05/02/2006 (2:13 pm)
Quote:
Is the .tgb file there a remnant from an earlier beta, and .t2d the way to go now?

Actually, the million dollar question is whether .tgb is going to replace .t2d. :)

.tgb has never been used as a file extension yet. With beta 2 we've used the current .t2d. Before that we had .lvl (although if I remember right the extension didn't matter, now it does).
#5
05/02/2006 (2:30 pm)
Great! Everything seems to work great now. I thought I'd tried it that way before and it didn't work. I must have typoed something. Anyway, I'm good to go, now.

Perhaps the '~' pathing doesn't work for the loadLevel function.

Thanks alot for your help.