Obj.save does not work as documented
by Phoenix Online Studios · in Torque Game Engine · 10/15/2006 (10:07 am) · 8 replies
Hi!
I'm having trouble with the save() method. What I want to do is to save several objects in the same file from a script, but the documented append option of save() does not work. (Supposedly, %obj.save("test.cs", true) would save with append and %obj.save("test.cs", false) would save with write.) I took a peek at the engine source code and it doesn't appear to support appending at all. If you set the append option to true, all it does is overwrite the file you have and only puts the OBJECT WRITE BEGIN and OBJECT WRITE END lines in there. I'm not sure what the second option is supposed to do, but it's not appending objects to files anyway.
Is there another, simple way to write objects to a .cs file with append or will I have to modify the engine to do this?
I'm having trouble with the save() method. What I want to do is to save several objects in the same file from a script, but the documented append option of save() does not work. (Supposedly, %obj.save("test.cs", true) would save with append and %obj.save("test.cs", false) would save with write.) I took a peek at the engine source code and it doesn't appear to support appending at all. If you set the append option to true, all it does is overwrite the file you have and only puts the OBJECT WRITE BEGIN and OBJECT WRITE END lines in there. I'm not sure what the second option is supposed to do, but it's not appending objects to files anyway.
Is there another, simple way to write objects to a .cs file with append or will I have to modify the engine to do this?
#2
10/15/2006 (2:43 pm)
Yeah, but I specifically want to output a bunch of objects with dynamic fields that will change a lot during development and would prefer not to have to manually specify/update each line I'm writing here.
#3
I don't understand where "append" came from.
However, the saving function does have a feature where it will replace only data between the "begin object write" and "end object write" markers, so you could filter the file to move those markers to the end, if you want to write a whole new object to the file.
10/15/2006 (3:44 pm)
Here's the documentation for SimObject::save():ConsoleMethod(SimObject, save, bool, 3, 4, "obj.save(fileName, <selectedOnly>)")
I don't understand where "append" came from.
However, the saving function does have a feature where it will replace only data between the "begin object write" and "end object write" markers, so you could filter the file to move those markers to the end, if you want to write a whole new object to the file.
#4
bit is what's confusing me. On TDN, it says that this argument is an append flag, but the source code suggests otherwise.
10/15/2006 (3:49 pm)
Yeah, the
#5
10/15/2006 (4:15 pm)
I think selectedOnly tells it to only save objects which are currently selected in the mission or GUI editor.
#6
10/15/2006 (7:01 pm)
You can/should update TDN if its wrong.
#7
10/15/2006 (8:07 pm)
I think you were confusing the documentation for class ActionMap (where the bool is for append) with the documentation for a regular SimBase object.
#8
10/16/2006 (9:36 am)
Yeah, you're right. My mistake. :P Anyway, I think the easiest solution to my problem is to simply add all the objects I want to save to a SimSet, and save that instead. If I need to add further data I can open that file with append in the normal way afterwards and add single lines.
Torque Owner Skylar Kelty
SkylarK
%file = new FileObject(); %file.openforwrite("~/test.cs"); %file.writeLine("blah"); %file.writeLine("blah"); %file.close(); %file.delete();or openforappend:
%file = new FileObject(); %file.openforappend("~/test.cs"); %file.writeLine("blah"); %file.writeLine("blah"); %file.close(); %file.delete();Openforwrite will delete everything in the file and then add the lines
Openforappend will add the lines to the end