openForWrite problem in TGB 1.7.4
by Mariano Burgos · in Torque Game Builder · 05/25/2009 (10:08 pm) · 5 replies
Hello,
i am trying to write a file using the function openForWrite, my code if as follows:
function writeFile()
{
%file = new FileObject();
if(%file.openForWrite("c:\k\tgb1.txt"))
{
%file.writeLine("Hello World!");
echo("File Written");
}
else
{
error("File is not open for writing");
}
%file.close();
%file.delete();
}
when i enter in the console and write "writeFile()", the response is "File Written", as if everything was Ok, however my file is not located in the computer, because i did a deep search, however when i specified the folling path of the filename: "~/data/files/tgb1.txt", the file is written in "AppData\Roaming\Independent\UntitledGame" folder. But that folder is not useful for us, we need a custom folder like that i mentioned.
Can anyone help me to write a file to any desired folder ?? our target platform is Windows (xp, vista, 2k, ...)
thank you very much:
Mariano.
i am trying to write a file using the function openForWrite, my code if as follows:
function writeFile()
{
%file = new FileObject();
if(%file.openForWrite("c:\k\tgb1.txt"))
{
%file.writeLine("Hello World!");
echo("File Written");
}
else
{
error("File is not open for writing");
}
%file.close();
%file.delete();
}
when i enter in the console and write "writeFile()", the response is "File Written", as if everything was Ok, however my file is not located in the computer, because i did a deep search, however when i specified the folling path of the filename: "~/data/files/tgb1.txt", the file is written in "AppData\Roaming\Independent\UntitledGame" folder. But that folder is not useful for us, we need a custom folder like that i mentioned.
Can anyone help me to write a file to any desired folder ?? our target platform is Windows (xp, vista, 2k, ...)
thank you very much:
Mariano.
#2
As you have the Pro version, changing this behavior would not be too difficult (look in engine/core/fileObject.cc for a start).
//PS: Upon closer inspection, turns out the above isn't 100% accurate as it's FileObject itself that does the prefpath mapping and not ResManager (which simply rejects opening a file for writes when not in the appropriate path).
05/26/2009 (12:05 am)
TGB does not permit writing outside the writable data folder (which is the the above-mentioned folder under Vista). FileObject uses the ResManager which exclusively works with the game asset directory and the writable data folder.As you have the Pro version, changing this behavior would not be too difficult (look in engine/core/fileObject.cc for a start).
//PS: Upon closer inspection, turns out the above isn't 100% accurate as it's FileObject itself that does the prefpath mapping and not ResManager (which simply rejects opening a file for writes when not in the appropriate path).
#3
Is there some setting somewhere that I need to change in order to be able to write to my local game directory somehow?
Whenever I use the openForWrite("./game/data/test.txt") function it writes the file to my Users/username/Library/Application Support/Independent/Untitled Game/game/gameScripts/game/data/test.txt
I've tried things like openForWrite("~/data/test.txt") and other iterations of writing to the file but it always puts the file in the directory path I mentioned.
Thanks in advance for any assistance.
David
06/22/2009 (8:07 am)
I'm having the same problem when trying to do the tutorial on File I/O on a mac, OSX Leopard. I can't get the file to write to my local game directory no matter what I try.Is there some setting somewhere that I need to change in order to be able to write to my local game directory somehow?
Whenever I use the openForWrite("./game/data/test.txt") function it writes the file to my Users/username/Library/Application Support/Independent/Untitled Game/game/gameScripts/game/data/test.txt
I've tried things like openForWrite("~/data/test.txt") and other iterations of writing to the file but it always puts the file in the directory path I mentioned.
Thanks in advance for any assistance.
David
#4
Yep, this is the hardwired behavior of FileObject. In fact, in a release setting this makes a lot of sense as you wouldn't want to write to the central installation directory (to which the current user may not even have write permissions) but rather to the user's data directory.
Note that FileObject also does the reverse mapping, i.e. if you open the file again, it automatically looks in the user data directory first and only then in the game directory.
If you still want to write into the game directory, compile fileObject.cc with TORQUE_PLAYER undefined. Just put a #undef TORQUE_PLAYER at the top after the #includes. That should do the trick.
06/22/2009 (8:21 am)
Yep, this is the hardwired behavior of FileObject. In fact, in a release setting this makes a lot of sense as you wouldn't want to write to the central installation directory (to which the current user may not even have write permissions) but rather to the user's data directory.
Note that FileObject also does the reverse mapping, i.e. if you open the file again, it automatically looks in the user data directory first and only then in the game directory.
If you still want to write into the game directory, compile fileObject.cc with TORQUE_PLAYER undefined. Just put a #undef TORQUE_PLAYER at the top after the #includes. That should do the trick.
#5
I was wondering what I was doing wrong, because I couldn't follow the tutorial exactly. Your explanation makes sense!
Kind regards,
David
06/22/2009 (9:22 am)
Thanks for the clarification, Rene :-)I was wondering what I was doing wrong, because I couldn't follow the tutorial exactly. Your explanation makes sense!
Kind regards,
David
Torque 3D Owner Marc Dreamora Schaerer
Gayasoft
you need to modify the io code to request the rights to do that from windows, which naturally also will trigger the common approval request window from Vista.
you are not allowed to write outside the users folder with a normal user account