Game Development Community

Resolved - OpenForWrite failing with relative paths

by Pronto Games Engineer1 · in Torque Game Builder · 11/01/2007 (5:09 pm) · 2 replies

Hello, I am having difficulty using TGB to write a file. I've read several examples from tutorials as well as several forum threads, and have tried all sorts of different approaches and each time I come up empty. I have a sneaking suspicion I am missing something obvious but I am spinning my wheels trying to find it. Can someone help me figure out what I am doing wrong? Here is the code snippet I am executing:

function testFileWrite()
{
%path = "~/test.txt";

%file = new FileObject();

if(%file.OpenForWrite(expandFilename(%path)))
{
echo("file opened for writing");
}
else
{
echo("file did not open for writing");
}

%file.writeline("test");
%file.close();
%file.delete();
}

In addition to the above path, I have tried the following, unsuccessfully:
%path = "./test.txt";
%path = "~/data/test.txt";//thinking maybe the game folder doesn't like things written in it
%path = "data/test.txt";
%path = "test.txt";
%path = "test.dat";//and various other extensions, with all the above prefixes

I have also tried with and without the expandFilename path function with all permutations. I have also tried
%file = new FileObject("FW");
and used FW.OpenForWrite etc. No luck

Interestingly, it DOES work with a fully qualified path:
%path = "C:/Code/Playpen/Torquemata/FileTest/game/test.txt";
But obviously this won't help me in the long run. I've stepped through it and everything looks in place (unfortunately, OpenForWrite wont let me step into it). I know that OpenForRead has an issue where you have to OpenForAppend first, so I even tried that with no luck. Any clues?

#1
11/01/2007 (6:40 pm)
Try this fix from Tetraweb's September 29th post. It has solved all of my write issues.
#2
11/02/2007 (9:35 am)
That did it! Thanks Steven S & Tetraweb.