Game Development Community

Using SimObject.save, but how do you load?

by Brandon James · in General Discussion · 03/07/2006 (8:30 am) · 3 replies

Hi All,

I'm trying to save some game data and I'd like to use the built in save feature of a ScriptObject. The data I'm saving is NOT part of the C++ code since I'm trying to do some rapid prototyping.

Here's what I do:

//--------------------------------------
%file = "/gameName/data.txt";
%foo = new ScriptObject();

%foo.bar = "aaa";
%foo.bally = "bbb";

%foo.save(%file);

%bax = exec(%file);
%bax.dump();
//---------------------------------------

Unfortunately, I get an error telling me that %bax has been given a value of 1 and that it isn't a valid object. Thus I cannot call dump on it. I look at it in the torsion debugger and also see that %bax is 1.

Here is the data that gets written to my file:

//--- OBJECT WRITE BEGIN
new ScriptObject() {
bar = "aaa";
bally = "bbb";
};
//--- OBJECT WRITE END


So it seems good on the save side. What am I doing wrong on the load?

Thanks for any help,

#1
03/07/2006 (8:44 am)
ExeC() a file will not return the file contents , one would have to read the file as a file object to do that

one thing you can do is name each script object to use it
%file = "/gameName/data.txt";
%foo = new ScriptObject(FRED);

%foo.bar = "aaa";
%foo.bally = "bbb";

%foo.save(%file);
FRED.delete(); //fred is now gone from memory
%bax = exec(%file);
//FRED has returned
FRED.dump();
#2
03/07/2006 (8:54 am)
I see.

Thanks for your help, this basically makes sence but now I'm confused about the scoping.

I thought that local variables started with % and globals started with $. Why does FRED work without either of these punctuation markers? What scope is FRED available in?

Thanks again
#3
03/07/2006 (9:23 am)
FRED is Global

look at the object sections of this resource