File writing issue
by Dracola · in Torque Game Engine · 11/14/2005 (7:14 pm) · 4 replies
I am useing %scriptFO.writeLine(%text); to write files made in an editor the problem I see happening is if I write something in the middle of a file it will write over since it replaces lines. bassically what I need is a way to insert lines without overwriting an old one. Does anybody know of a way to do this?
About the author
#2
%i = %i@"<>NEWLINE><"@%overwrittenline
then when it comes I stop overwriting I can split it up by turning all the "<>NEWLINE><"'s into paragraphs.
11/14/2005 (8:50 pm)
Well in that case I have a pretty ugly answer to my own question every time I replace a file I add it to %i%i = %i@"<>NEWLINE><"@%overwrittenline
then when it comes I stop overwriting I can split it up by turning all the "<>NEWLINE><"'s into paragraphs.
#3
1. Read the entire file and parse it into your data structures.
2. Modify the data in memory (you can re-organize it here)
3. Write the entire file back to disk.
If you're just appending data to the end, you can just add the new stuff. But if you're modifying stuff, or adding in the middle, the surest and simplest way is what I described above. There are more complicated methods, like defining an exact binary file format (where you have a limit of say 1024 bytes for a text field, and it always takes up that much).
11/15/2005 (10:06 am)
This isn't just a Torque thing... all platforms I know of work with files this way. The way I generally do this (and I think it's a fairly common way) is as follows:1. Read the entire file and parse it into your data structures.
2. Modify the data in memory (you can re-organize it here)
3. Write the entire file back to disk.
If you're just appending data to the end, you can just add the new stuff. But if you're modifying stuff, or adding in the middle, the surest and simplest way is what I described above. There are more complicated methods, like defining an exact binary file format (where you have a limit of say 1024 bytes for a text field, and it always takes up that much).
#4
11/15/2005 (10:42 am)
What alan said.
Torque Owner Cinder Games