Game Development Community


#1
03/29/2005 (1:33 am)
Thats sort of wierd. I would check the gui files associated with the map editor and see if there is a path hardcoded in there. I'm thinking maybe since all the map editor gui's are in the common folder, maybe it looking there also? I don't have the code in front of me because I'm at work. So I don't know for sure.
#2
03/29/2005 (5:03 am)
Have you tried adding "~/client/maps/" or maybe "./maps/" to the begining of the filename variable?
#3
03/29/2005 (6:19 am)
Directories confused the heck out of me when I started with TGE as well. Withouth seeing what your specifying as a filename its hard to say what your problem is but let me give you a couple tips.

1) You really should get into the habit of passing filenames through expandFilename() at all times.
2) The active directory is always the directory that contains the active running script (Which IIRC gets confusing when one script is called from another, but I don't rememeber how that changes things as I just woke up)
3) Standard relative path symbols can be used such as "." to indicate start in the active directory, ".." go up to the active directorys parent and "~" which means start in the base directory for the mod/game
4) TorqueScript for security reasons is designed to not allow file actions outside the directory structure of the game. Though last i'd heard you could in fact write outside, you just can't read. Might have fixed the write since then though.
#4
03/29/2005 (6:21 am)
To accurately, every time, write to the maps directory of the active mod/game oyu would do:

%filename = "~/client/maps/mymap.scroller";
%file = new FileObject();
%file = openForWrite(expandFilename(%filename));
%file.wrtieLine("Hello World 123");
%file.close();
#5
03/29/2005 (7:03 am)
In my tool I found that it was easier for me to use the absolute path from the T2D executable.
#6
03/29/2005 (7:49 am)
You can also use the save file function. I forget what it is off the top of my head, but it displays a gui and you can choose what dir and what you want to call the file. It uses a callback (it calls a function that you specify).
It passes to the function the absolute path and file name. Take a look at the code in my tool for an example on how to use it. I'm not home but the easy way to find it is to take a look what function the "save to script" button calls.
#7
03/29/2005 (8:23 am)
Heres a GUI I adapted from the gui save function (using some of the same stuff ChazCross was saying)...

should be a good place to start from

//--- OBJECT WRITE BEGIN ---
new GuiControl(SaveScriptGui) {
   profile = "GuiDefaultProfile";
   horizSizing = "right";
   vertSizing = "bottom";
   position = "0 0";
   extent = "640 480";
   minExtent = "8 2";
   visible = "1";

   new GuiWindowCtrl() {
      profile = "GuiWindowProfile";
      horizSizing = "right";
      vertSizing = "bottom";
      position = "254 65";
      extent = "300 300";
      minExtent = "8 2";
      visible = "1";
      maxLength = "255";
      resizeWidth = "1";
      resizeHeight = "1";
      canMove = "1";
      canClose = "1";
      canMinimize = "1";
      canMaximize = "1";
      minSize = "50 50";

      new GuiTextEditCtrl(SaveScriptText) {
         profile = "GuiTextEditProfile";
         horizSizing = "right";
         vertSizing = "bottom";
         position = "8 256";
         extent = "224 18";
         minExtent = "8 2";
         visible = "1";
         maxLength = "255";
         historySize = "0";
         password = "0";
         tabComplete = "0";
         sinkAllKeyEvents = "0";
      };
      new GuiButtonCtrl(SaveScriptButton) {
         profile = "GuiButtonProfile";
         horizSizing = "right";
         vertSizing = "bottom";
         position = "236 256";
         extent = "58 18";
         minExtent = "8 2";
         visible = "1";
         command = "SaveScriptGui.saveScript(scriptEdit.getValue(), SaveScriptText.getValue());";
         text = "Save";
         groupNum = "-1";
         buttonType = "PushButton";
      };
      new GuiButtonCtrl(SaveScriptCancel) {
         profile = "GuiButtonProfile";
         horizSizing = "right";
         vertSizing = "bottom";
         position = "221 277";
         extent = "73 18";
         minExtent = "8 2";
         visible = "1";
         command = "canvas.popDialog(SaveScriptGui);";
         text = "Cancel";
         groupNum = "-1";
         buttonType = "PushButton";
      };
      new GuiPopUpMenuCtrl(SaveScriptDirectoryList) {
         profile = "GuiPopUpMenuProfile";
         horizSizing = "right";
         vertSizing = "bottom";
         position = "98 26";
         extent = "146 21";
         minExtent = "8 2";
         visible = "1";
         maxLength = "255";
         maxPopupHeight = "200";
      };
      new GuiScrollCtrl(SaveScriptScroll) {
         profile = "GuiScrollProfile";
         horizSizing = "right";
         vertSizing = "bottom";
         position = "8 50";
         extent = "286 202";
         minExtent = "8 2";
         visible = "1";
         willFirstRespond = "1";
         hScrollBar = "alwaysOn";
         vScrollBar = "alwaysOn";
         constantThumbHeight = "0";
         childMargin = "0 0";

         new GuiTextListCtrl(SaveScriptFileList) {
            profile = "GuiTextListProfile";
            horizSizing = "right";
            vertSizing = "bottom";
            position = "2 2";
            extent = "214 128";
            minExtent = "8 2";
            visible = "1";
            enumerate = "0";
            resizeCell = "1";
            columns = "0";
            fitParentWidth = "1";
            clipColumnText = "0";
         };
      };
      new GuiTextCtrl() {
         profile = "GuiTextProfile";
         horizSizing = "right";
         vertSizing = "bottom";
         position = "43 28";
         extent = "47 18";
         minExtent = "8 2";
         visible = "1";
         text = "Directory:";
         maxLength = "255";
      };
   };
};
//--- OBJECT WRITE END ---
#8
03/29/2005 (8:23 am)
Heres the script for it (i have it in the same file)

function SaveScriptGui::onWake(%this)
{

	%this.loadDirectoryList("client.cs");
}
function SaveScriptGui::saveScript(%this, %data, %name)
{
	%savePath = "";
	%filePath = %savepath @ %name;

	%file = new FileObject(); 
	if(%file.openForWrite(%filePath))
	{
		echo("file opened for writing"); //for debug
	} else
	{
		echo("file did not open for writing");//for debug
	}

	

	echo("starting to save this data:" SPC %data SPC ", under the file name of:" SPC %name);
	
	%file.writeLine(%data);
	%file.close();
	canvas.popDialog(SaveScriptGui);
}

function SaveScriptGui::loadDirectoryList(%this, %currentFile)
{
   echo("attempting to load a directory list");

// Fill the Directory Drop Down
   %i = 0;
   %unique = 0;
   SaveScriptDirectoryList.clear();
   for(%file = findFirstFile("*"); %file !$= ""; %file = findNextFile("*"))  
      if (strstr(%file, "/CVS/") == -1)
      {
         %path = filePath(%file);
         if (!%unique[%path]) 
         {
            %i++;
            %unique[%path] = %i;
            SaveScriptDirectoryList.add(%path, %i);
            if (!%hasPath)
            {
               if (isFile(%path @ "/" @ %currentFile))
               {
                  %currentFile = %path @ "/" @ %currentFile;
                  %hasPath = true;
               }
            }
         }
      }
   SaveScriptDirectoryList.sort();
   
   // select the directory represented by current file
   if ( %unique[filePath(%currentFile)] )
      SaveScriptDirectoryList.setSelected( %unique[filePath(%currentFile)] );
   else
      SaveScriptDirectoryList.setSelected( 1 );
   SaveScriptText.setValue(filePath(%currentFile) @ "/" @ fileName(%currentFile));
}

function SaveScriptDirectoryList::onSelect(%this, %id)
{
   echo("attempting to load a file list");

   %fileType = "*.cs";


   // when a directory is selected put it's files in the file list
   SaveScriptFileList.clear();
   %fileType = %this.getTextById(%id) @ "/" @ %fileType;
   for(%file = findFirstFile(%fileType); %file !$= ""; %file = findNextFile(%fileType))  
      if (strStr(%file, "/CVS/") == -1)
         SaveScriptFileList.addRow(%i++, fileName(%file));
   SaveScriptFileList.sort(0);
   %id = %this.getTextById(%id);
   $scriptEditor::saveFilePath = %id;
   SaveScriptText.setValue($scriptEditor::saveFilePath);
} 

function SaveScriptFileList::onSelect(%this, %id)
{
   // when a file is selected change the current filename
   SaveScriptText.setValue($scriptEditor::saveFilePath @ "/" @ fileName(%this.getRowTextById(%id)));
}
#9
03/29/2005 (3:23 pm)
That was written from the recesses of my dark mind so it may have some errors in it. I'll check the code when I get home.

RE: It making a directry named ~.. Did you use the expandFilename?
#10
03/29/2005 (5:34 pm)
It wont let you access files outside of T2D for some very good security reasons :)