Game Development Community

SceneWindow2D.loadLevel("~/data/levels/%level") question

by Jon Mitchell · in Torque Game Builder · 04/20/2007 (12:25 pm) · 8 replies

I have been using the following to load a level:

sceneWindow2D.loadLevel("game_directory_name/data/levels/level1.t2d");

I recently tried to what I use for loading most other data by replacing the game directory with a tilde:
sceneWindow2D.loadLevel("~/data/levels/level1.t2d");

But I get an error that it is an invalid file. Is there some rule that I have not found while searching that you must use the full path?

#1
04/20/2007 (3:37 pm)
Levels can't be loaded with ~
Had to find this out the "wall" way as well (ie bump into the wall when trying to do so ^^)
#2
04/20/2007 (8:17 pm)
Not all of the file functionalities, in this case 'loadLevel', support the expansion characters "." and "~" ...
#3
04/21/2007 (5:38 pm)
For anyone else who bumps into this thread and wants some answers, you can still use "~" and "." in your loadLevel() call. Just wrap it with a call to expandFilename():
sceneWindow2D.loadLevel(expandFilename("~/data/levels/level1.t2d"));
#4
04/22/2007 (2:29 am)
Hmm ... thank you :-)
*would be simpler if loadLevel did that itself but ok ^^*
#5
04/23/2007 (5:22 pm)
That is good info to know, thank you Eric!

Is there a limitation of some sorts that prevents the expansion characters being used, or is just something that needs to be polished and might be in a later revision of tgb?

Also I have to claim ignorance, but what is the difference between using . and ~
#6
04/23/2007 (6:05 pm)
It's just something they didn't do for loadLevel ;)

and . means "current directory" where ~ means "relative to game" ...

"current directory" is relative to the script using it, so if your script is in gameMod/gameScripts/something/script.cs then "." would point to gameMod/gameScripts/something ... where as ~ would point to gameMod/
#7
04/23/2007 (6:16 pm)
Meh, my guess is that those are used as they are in *nix style environments.

"~" is your home directory (the base directory of your game in TGB).
"." is the current working directory (not sure how this would be used in script but...).

I could be completely off the mark, though. Perhaps in Torque-land they are the same thing? Someone please correct me on this if I'm incorrect.

My guess is that most functions do an expandFilename() call automatically whereas the loadLevel() function (a function written in Torquescript, by the way) does no such thing.

The function fails on the calls to isFile(). I believe that that function is platform-specific (?). What OS are you running? Using "~" without expandFilename() in OSX 10.4.9, at least, has this problem...

EDIT: I did some mucking around in the source code and it looks like something funky is going on. isFile() calls expandScriptFilename() already. I don't know why calling expandFilename() on a string before passing it to isFile() works but...

Bug in isFile() code?
#8
04/23/2007 (8:05 pm)
Y'know -- I never dug into the loadLevel issue ... after looking through the code, it seems quite odd that the loadLevel doesn't support the expando's ... the issue is present on the Windows platform, or least ... it was in previous versions, I haven't bothered to check the latest 1.1.3 or 1.5 source ... maybe they fixed it since I stopped bothering to try to do it ... ;)