Game Development Community

Base directory

by John Vanderbeck · in Torque Game Engine · 03/22/2004 (2:36 pm) · 7 replies

Ok I keep runing into this problem and its driving me crazy. Just how is the "base" directory determined? It seems to be different in different scripts, and I can't seem to nail it down. Sometimes its the executeabler directory or working directory, other times its the mod/game directory (starter.fps for example) other times its the UI directory and yet other tyimes it seems to be the "data" directory. Ug.

Can anyone make some sense to this for me? How can I tell where it will be for the script i'm writing?

#1
03/22/2004 (3:44 pm)
In the same folder as your executable look at main.cs right near the top, $basemods and $usermods.

I'm not sure what kind of script you're writing; so, I have no idea how to make some sense for you.

The main.cs in your mod folder just holds your defaults and overrides some functions that are in common.
#2
03/23/2004 (6:19 am)
I'm a bit surprised by your question John but it's located in the main.cs and is default for all the releases I have seen to today.

On the other hand it seems that I am missing your point, or something.
#3
03/23/2004 (6:40 am)
Um yeah neither of you guys really answered my question :)

Base Directory = base of relative paths. EG instead of doing "C:\Torque\Example\main.cs" you can do "main.cs" because the base directory is "C:\Torque\Example\".

However, that doesn't always seem to be the case. Different scrpits seem to have or use different base paths. IE there doesn't seem to be one single base directory in a running Torque application.

For example, the mission spec makes it look like when its run, the base directory is "c:\torque\example\starter.fps\data".

A lot of the scrpits also make reference like this "./scripts/blah.cs" which means the base directory is yet again different.

Is the base directory always the directory that the particular active script file is in?
#4
03/23/2004 (11:31 am)
Yes. If you use the "./blaha/hey.cs" it will always point to the current location of the executed script and then forward to whatever location that is defined.

If you would to remove the dot; you would tell the script to go from it's parent rather than from the location of the script.

If the script resides in the same directory, you don't use anything in front of the filename but you CAN use the full path.
Again if something is moved, that won't work and you'll have to modify it.

That's the three only ways of doing that I know.
#5
03/23/2004 (7:33 pm)
There's another special char, tilde (~). I believe it's something like "the root of this mod" but I don't remember offhand. So if you had two "mods", common and starter.fps and a script in a subfolder of starter.fps referenced "~/client..." then that would point to the starter.fps folder. I'm not sure if that's right and if that's what it does, but thought I'd throw it out there.

-Ner
#6
03/23/2004 (9:36 pm)
Yeah, its basically like linux.

. means this folder, so ./script.cs means the script.cs in the folder of the current script.
eg, if i have fps/server/scripts/foo.cs, and I put
exec("./bar.cs"); in there, it'll executed the file at
fps/server/scripts/bar.cs (the dot gets expanded to fps/server/scripts)

.. means the parent folder

~ means the root folder for the mod/game. so ~/client/scripts/bar.cs gets expanded to
fps/client/scripts/bar.cs
#7
03/24/2004 (5:27 am)
Ok, yeah I understand the symbology, but i'm used to ".", "..", and "~" being all relative to the same directory, not it changing all over the place :p

But I see it now. It always based off whatever directory the currently runing script is in. Weird but now that I know it i'm good.

The mission spec used in FindFirstFile etc must be different than I thought. It is listed as "*/missions/*.mis" which originally I thought meant it was using starter.fps/data as the base, but I guess not. I guess the "*" in front means anywhere you find a missions directory.