I'm having a hell of a time trying to get persistent data to work. No matter what I do, the data never actually makes it into the savegame file.
Here's what I'm doing with my scripts that need access to the data:
(Link to the ascData class:
http://fractalsoftworks.com/forum/index.php?topic=5061.msg116257#msg116257 )
ascData DATA = (ascData) Global.getSector().getPersistentData().get("ASCDATA");
I declare DATA as a class data member, and assign it to the ascData instance stored under the key "ASCDATA".
............
if (DATA == null) {
DATA = new ascData();
}
Because that might be null if nothing was stored there, so I make sure to create a new instance.
......... Then my scripts do whatever it is they do, and they usually end up modifying "DATA" in some way.
At the end of the script:
Global.getSector().getPersistentData().put("ASCDATA", DATA);
I place the modified DATA object into the game's persistent data map under the key "ASCDATA".
The way I see it, this should be happening:
My scripts, when they run, load in the persistent data. They modify it as necessary. They save it back into the persistent data map, replacing the former "DATA" object. The next time a script runs, it uses the updated "DATA" object, and everything is fine.
This works as long as the game isn't restarted. As soon as it is, everything goes back to the ascData class's defaults for some reason. I don't understand why it isn't saving. This is all that appears in the savegame:
<string>ASCDATA</string>
<data.asc.ascData></data.asc.ascData>
Obviously, the persistent data for the key "ASCDATA" is totally empty, other than the reference to the class itself.
Is there something blatantly obvious that I'm doing wrong here? Because I've searched for hours and tried a million different things, and have had absolutely no progress whatsoever.