Game Development Community

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.

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


#1
01/23/2009 (10:56 am)
Well I figured out that you must do:

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.
#2
01/23/2009 (11:06 am)
Lol well it looks like it got stored in common. I guess this is a way to learn. I hope this helps someone else out and saves them time. ;)
#3
01/23/2009 (3:00 pm)
Thanks for posting your progress!