Game Development Community

Problem with simple, write to text file!!

by Valerie Butler · in Torque Game Engine · 08/04/2009 (3:05 pm) · 3 replies

Hi I want to simply use script to write to a text file but for some reason it is not working... I am using the following...

%file = new FileObject() ;

echo("%file.openForWrite("test.txt")") ;

%file.writeLine("text") ;

%file.close() ;
%file.delete() ;

Does any body see anything I should have and dont, or what am I doing wrong? :-(

Thank You!

#1
08/04/2009 (4:20 pm)
Change:
echo("%file.openForWrite("test.txt")") ;
to:
%file.openForWrite("test.txt");
#2
08/05/2009 (12:30 am)
Hi thanks for reply, didnt realise I still had that line in,

I changed it to ...

%file = new FileObject() ;
echo("Creating File...");
%file.openForWrite("test.txt);
echo("Finished Creating File...");

%file.writeLine("text") ;

%file.close() ;
%file.delete() ;


This returns

Creating File...
0
Finished Creating File..

If I type the code into the console window during gameplay I get the error that "Unable to find object: '' attempting to call function openForWrite"

Thanks for any help!
#3
08/05/2009 (7:25 am)
I guess the problem is, that you didn't specify a path for the file. The path should also be a module path. So if you use starter.fps try save it to
"starter.fps/test/test.txt" this should work. Also "test/test.txt" should work but you'll get trouble loading it after restart because it's not a mod-path. If I remember right after saving a dummy file into the directory you can also load files from there. It's all resource manager related, which scans the mod-paths, when engine starts up.

In console try using $file instead of %file.