WriteLine() Does not seem to work for me.
by Michael Cozzolino · in Torque Game Engine Advanced · 01/22/2009 (2:12 pm) · 3 replies
I'm posting in TGEA since that's what Engine I'm working in. 1_7_0 specifically. I could not find any reports of this not working other than some TGB users. Seems they couldn't open files to be written. I can open the file but seems as though the WriteLine() Does nothing. Any suggestions? Code is below.
My output to the console when the function is called is:
Reads line by line the first file and outputs fine
Reads line by line the second file and outputs fine
Echos out "We should be writing to file: Happily Writing Text"
Does not WriteLine() "Happily Writing Text" into TestingWrite.txt
function GetArcadeMenuNames_Scores()
{
// Reading Names and displaying in console
%ArcadeNames = new FileObject();
%ArcadeNames.openForRead("scriptsAndAssets/data/missions/Arcade_Names.txt");
%lineCount1 = 0;
while ( !%ArcadeNames.isEOF() )
{
%line1 = %ArcadeNames.readLine();
echo(%line1);
%lineCount1++;
}
%ArcadeNames.close();
// Reading Scores and displaying in console
%ArcadeScores = new FileObject();
%ArcadeScores.openForRead("scriptsAndAssets/data/missions/Arcade_Scores.txt");
%lineCount2 = 0;
while ( !%ArcadeScores.isEOF() )
{
%line2 = %ArcadeScores.readLine();
echo(%line2);
%lineCount2++;
}
%ArcadeScores.close();
// Trying to write to a file
%Writing_TestingWrite = new FileObject();
if(%Writing_TestingWrite.openForAppend("./scriptsAndAssets/data/missions/TestingWrite.txt"))
{
%Writing_TestingWrite.writeLine("Happily Writing Text");
echo("We should be writing to file: Happily Writing Text");
%Writing_TestingWrite.close();
}
else
{
echo("Error in opening file... Does it exist?");
}
%Reading_TestingWrite = new FileObject();
%Reading_TestingWrite.openForRead("scriptsAndAssets/data/missions/TestingWrite.txt");
%lineCount3 = 0;
while ( !%Reading_TestingWrite.isEOF() )
{
%line3 = %Reading_TestingWrite.readLine();
echo("TestingWrite "@ %line3);
%lineCount3++;
}
%Reading_TestingWrite.close();
}My output to the console when the function is called is:
Reads line by line the first file and outputs fine
Reads line by line the second file and outputs fine
Echos out "We should be writing to file: Happily Writing Text"
Does not WriteLine() "Happily Writing Text" into TestingWrite.txt
About the author
Indie Developer in the Albany NY area. iOS, PC, Mac OSX development. http://itunes.apple.com/us/artist/michael-cozzolino/id367780489
Torque 3D Owner Michael Cozzolino
Big Monk Games
if( isWriteableFileName( %filename ) )
and read the file before you open it up for writing. Found that in guiEditorCanvas.ed.cs
Now my problem is that I have a file that is getting written to but a hard copy of the file does not exist. Well one does exist but I don't think it is the one Torque is reading from because it has no data. It is reading from a saved copy somewhere because I threw in an append and each time I run TGEA and echo out when reading the file it kept adding whatever new thing I had along with all of the previous data that was saved.
Any idea on what the hell I am doing wrong? I know this works since it is used to write out gui.