Author Topic: Suppose I try to log some data in this method - what if I crash?  (Read 1222 times)

Got a theory for a logging mechanism that logs data to file repeatedly.
More specifically, positions of a specified player.

Now, I hear tell that fileObject::openForWrite/Read/Append are very laggy methods and should be used sparingly.

Here's my theory:

new fileObject("test");
test.openForAppend("targetfile.txt");


now pause and wait for data to be written. perhaps a schedule loop, or some other method for writing data.
test.writeLine("blah data here");

Never close the fileobject until, say, the target leaves or some other event occurs.

Now, here's my question: What if the server crashes?
Will the file become corrupted?
Will it simply run the same as calling test.close();?

anyone? I presume the file will simply close then that's that, and that's what I heard, but I would like confirmation.

From my experience, I think the file is fine and it's just as if the fileObject closed it.

From my experience, I think the file is fine and it's just as if the fileObject closed it.
My experience coincides with this as well

The data is instantly written to the file once you do .writeline
When the game crashes, it's no longer using the file, thus it's now 'closed'.


Pretty sure this is how the console.log works anyways so it should be fine.

How do I erase the data written in a file with %file.writeline, without calling openforwrite again

Operating systems will close the file if the program suddenly terminates.

Operating systems will close the file if the program suddenly terminates.
okay.
Pretty sure this is how the console.log works anyways so it should be fine.
do you know where this functionality is defined?

How do I erase the data written in a file with %file.writeline, without calling openforwrite again
You cannot
Welcome to torque file I/O


Welcome to Torque Game Engine, leave all sense at the door.

You cannot
Welcome to torque file I/O
I really don't think that's possible in any language.

Welcome to Torque Game Engine, leave all sense at the door.
Also, take all headgear (including glasses/contacts) off and leave them in the shoe box next to the hat rack with scarves and bikinis on it. At all times keep a severed head around your neck for voodoo magic.

Also, take all headgear (including glasses/contacts) off and leave them in the shoe box next to the hat rack with scarves and bikinis on it. At all times keep a severed head around your neck for voodoo magic.
we should make a SCP out of this

You cannot
Welcome to torque file I/O
Don't dis torque's I/O system for that, you can't delete a line in a file without opening it, ever, not even in c++, not in C. It's common to open a file before writing new information to it (i.e. a null value).
Now that that's over, has OP been answered yet? wasn't there a resounding "No, it won't corrupt the file"?
NINJA EDIT: Ok, so you can do it in assembly... but its not a scripting language, therefore doesn not count.
« Last Edit: August 09, 2012, 05:40:49 PM by wizzlemanizzle »

Don't dis torque's I/O system for that, you can't delete a line in a file without opening it, ever, not even in c++, not in C, nor assembly. It's common to open a file before writing new information to it (i.e. a null value).
He's right.

Now that that's over, has OP been answered yet? wasn't there a resounding "No, it won't corrupt the file"?
Yes, I answered it.

do you know where this functionality is defined?
Pretty sure the console stuff is in the engine itself.