Game Development Community

Trouble Appending to file

by Jeff Trier · in Torque Game Engine · 04/29/2003 (7:16 pm) · 1 replies

Hi all,

I am trying to save a variable to the end of a file with this code:

function SaveData(%filename, %Data){ // Write Data to end of file
	%file = new FileObject();
	%file.openforAppend(%filename);
	%file.writeLine(""); // Keep from appending to end of last line
	%file.writeLine(%Data);
	%file.close();
	%file.delete();
}

function SaveInfo(){
        %SaveData = "TestLine";
	%filename = "fps/server/scripts/armies/armyData.cs";
	
	SaveData(%filename, %SaveData);       
}


It works with only one flaw. It likes to place an extra blank line after the newly added line.

For example, if the variable was appended to line 22, there would be a new blank line in line 23:
line 22: TestLine
line 23:

Is there a way to keep this new line from being created? This may sound trivial, but when I save multiple lines with this method, it creates gaps between them.

Thanks,
-Jeff

About the author

Originally a Classical/Metal musician, I've always been attracted to anything involving computers, including: Networking, PC Building and Repair, software design and coding. I've been involved with game design and development for over 10 years.


#1
05/01/2003 (1:57 pm)
I figured it out. After I modified the "save file to be" by deleting some test lines and then removing "%file.writeLine("");" from my save code, it worked.

Thanks,
-Jeff