Game Development Community

Problems with built-in file IO tutorial

by Joaquin Maguire · in Torque Game Builder · 03/25/2010 (3:51 pm) · 4 replies

Looking at the file IO tutorial in the built-in Torque docs, I copied this method:

function writeFile()
{
    %file = new FileObject();
    if(%file.openForWrite("~/data/files/test.txt"))
    {
        %file.writeLine("Hello World!");
        echo("File Written");
    } 

    else
    {   
        error("File is not open for writing");
    }
    %file.close();
    %file.delete();
}

I then run my game, open the console and type writeFile(). The console echoes "File Written," so presumably the program thinks everything is fine. However, nothing is written, even when I add a file for it to write to. It seems like this should be fairly straightforward, what am I missing?

#1
03/25/2010 (4:04 pm)
Data is not written to your installation directory, but to your Application Data directory. In Windows XP, go to "Run..." and type in (without the qutoes) "%APPDATA%". In Windows Vista or 7, just type "%APPDATA%" into the start menu text box.

This will take you to your Application Data directory. If you sort by the date, you'll probably find the directory it added your file to in the most recently added directory. In a default project, that will be "Independent/UntitledGame".
#2
03/25/2010 (4:31 pm)
Thank you.
#3
04/01/2010 (10:13 am)
Bingo!
#4
03/16/2011 (4:19 am)
Did any method to save the file in the directory that i wish to be?