Game Development Community

Directory Location of Torque

by Chad Kilgore · in Torque Game Builder · 03/21/2007 (12:35 pm) · 8 replies

I integrated Prairie Games' browser and now I am attempting to use the browser to view files on a user's computer. My problem is that I don't know the absolute path for Torque. I need to now the path similar to "C:/Documents and Settings/Administrator/Administrator's Documents/" to where Torque Game Builder is executing. Does Torque have a command or variable that I can use to determine this path? Thanks.

#1
03/21/2007 (12:42 pm)
@Chad, can I inquire as to why you need to know the absolute path to torque?
#2
03/21/2007 (2:41 pm)
I'm creating a faux website that is stored on the local computer. The browser will the enable players to visit this local website. But in order for the browser to navigate to the file, just as it is with a normal web browser, the url address needs to be the absolute path. If I can determine the path to Torque then I can add the relative path to the string.
#3
03/21/2007 (3:00 pm)
@Chad, does the browser resource not respect "relative" paths?

You can try "expandFileName", though I'm not sure if it expands it to a fully qualified file path, or just a fully qualified relative file path to the TGB.EXE ...

You could, depending on your abilities ... either have the installer for your game write out the install directory to a file in the TGB.EXE directory, and read it in at game start to get the path ... or ... browse through the platform code in the C++ and find an OS-specific function for retrieving the current EXE path ... usually, the path of the program is passed into the EXE's by the OS as the first parameter ... so if you find the demoGame.cc or main.cc (can't remember which one) ... you can find the main() entry-point to the engine, and grab the first parameter and store it somewhere and expose it back to TorqueScript ... if it's not already ...

I don't have the TGB Reference handy at the moment ... but check the Console Functions section of the TGB Docs and see if there's a useful function in there ...
#4
03/21/2007 (4:37 pm)
I haven't seen any function.
#5
03/21/2007 (4:54 pm)
Look in the documentation under console functions->file io. The function you are after is getworkingdirectory. This will return the absolute filepath of the TGB.EXE to you. I am not sure if it works across platforms.
#6
03/21/2007 (5:28 pm)
That worked perfectly. Thank you.
#7
03/21/2007 (7:27 pm)
@Guy, anything exposed through TorqueScript should be cross-platform ... all three supported platforms support the 'working directory' concept, as mentioned above -- it's passed in as the first param in windows and linux (OSX is based on BSD, so it would also do the same, I presume)
#8
03/21/2007 (8:21 pm)
@Dave, that was what I assumed. I only have a windows platform to test on and I didn't feel like digging through the source to verify it was cross platform. Just laying down a disclaimer to cma :)

@Chad:
Glad that worked for you.