Writing a file in TGB 1.7.5 not working
by Arden · in Torque Game Builder · 08/09/2010 (7:45 pm) · 7 replies
Hiya folks, when I run the following tutorial code in the console, I get the "File Written" echo text back, but the file test.txt is nowhere to be found in that directory. I did a full search as well through my drive and did not find it. I also tried writing in the full path to no avail. I use Vista. Any ideas what the problem might be? Thanks in advance for any help.
function writeFile()
{
%file = new FileObject();
if(%file.openForWrite("./game/data/test.txt"))
{
%file.writeLine("Hello World!");
echo("File Written");
}
else
{
error("File is not open for writing");
}
%file.close();
%file.delete();
}
function writeFile()
{
%file = new FileObject();
if(%file.openForWrite("./game/data/test.txt"))
{
%file.writeLine("Hello World!");
echo("File Written");
}
else
{
error("File is not open for writing");
}
%file.close();
%file.delete();
}
#2
This is mind blowing. I'm the only user running this machine as an administrator. Also, I checked in the users folder. Also not there.
Seems that TGB has an issue with writing files in Vista, or at least in the version I have. I will be trying it on an XP machine later on, but hopefully a fix can be found, as I expect many client machines will be running Vista...
08/09/2010 (10:48 pm)
Thanks William, appreciate that. I pasted your code into the funtion but unfortunately the problem seeems that I can't open the file for write. For example, when running your code, the writeLine("TEST") is never processed unless I remove the condition for testing if it's open for write. This is mind blowing. I'm the only user running this machine as an administrator. Also, I checked in the users folder. Also not there.
Seems that TGB has an issue with writing files in Vista, or at least in the version I have. I will be trying it on an XP machine later on, but hopefully a fix can be found, as I expect many client machines will be running Vista...
#3
08/11/2010 (4:09 am)
I had problems with the file IO in TGB on vista to. Its much better on Windows 7. However, I found that on Vista the XML file IO works alot better. Im not sure if the XML does work better on Vista but thats the results I got.
#4
08/12/2010 (3:51 am)
This issue seems unsovable. Hopefull a new version of TGB will fix that, or maybe a Vista patch :)
#5
I suspect you'll see this:
Cut it down to just "openforwrite("test.txt")", and it will write the file where it belongs (on Vista)... in the directory Benny pointed out above.
If you really MUST write to the game's directory (and you shouldn't really...), check first the script source for the level editor (since it obviously can write to the levels directory), and then the engine source if the script source doesn't help.
(I am using heavily-modified 1.7.4... but as far as I can tell, the file I/O code hasn't changed in 1.7.5's source)
08/12/2010 (11:40 pm)
Check your log file...I suspect you'll see this:
Quote:
getPrefsPath - Filename (./game/data/test.txt) cannot be relative.
Cut it down to just "openforwrite("test.txt")", and it will write the file where it belongs (on Vista)... in the directory Benny pointed out above.
If you really MUST write to the game's directory (and you shouldn't really...), check first the script source for the level editor (since it obviously can write to the levels directory), and then the engine source if the script source doesn't help.
(I am using heavily-modified 1.7.4... but as far as I can tell, the file I/O code hasn't changed in 1.7.5's source)
#6
08/23/2010 (2:43 pm)
Thanks a lot Tim, I'll give it a shot and let you know how it goes.
#7
Thanks a lot.
11/01/2010 (8:02 am)
Dear All, I have a same problem, when I try to write a file on TGB 1.7.4 running on Mac. Program write successfully but when I close program and read file. It does not work. I did many search but still can not be resolved. Who has experience at this please help me.Thanks a lot.
Torque 3D Owner Benny Peake
%path = "game/savedata/File.sav"; %fo = new FileObject(); %fo. openForAppend(%path); %dataFile = expandFileName(%path); if(isWriteableFileName(%dataFile)) { if(%fo.openForWrite(%dataFile)) { %fo.writeLine("TEST"); %fo.close(); } %fo.delete(); }also in vista, if your not running it as an admin, it will write to users/[your user]/AppData/Roaming/[your company name]/[your game name]/[the path you put in]