YASLQ (Yet another save/load question)

After reading several other save/load threads, I understand that implementing Savable to individual non-spatials is required for proper save/load functionality. However, I’m using custom classes that extend spatial (Spatial -> Node -> InteractiveNode(from t0neg0d gui) -> GameObject). My question is: since I’m inheriting the savable implementation from Spatial, do I still have to implement Savable in the “GameObject” classes? Also I’m receiving an InstantiationException because the GameObject classes don’t/can’t have empty constructors due to their superclass requirement of super(Screen). I assume that I’m not saving the screen object to disk or this would work - right?

These very well may be simple Java questions as I’m still learning the language. Thanks for reading and feel free to flame the post as long as you provide some helpful comments too :wink:

You do not need to implement Savable read/write unless you have properties you want to persist.
All classes that implement Savable should have an empty constructor, otherwise they cannot be serialized. I guess if t0neg0d GUI’s InteractiveNode does not have an empty constructor, then it cannot be serialized.

@Momoko_Fan said: You do not need to implement Savable read/write unless you have properties you want to persist. All classes that implement Savable should have an empty constructor, otherwise they cannot be serialized. I guess if t0neg0d GUI's InteractiveNode does not have an empty constructor, then it cannot be serialized.

So, is there no way to bypass the empty constructor? Or tell certain objects to pass arguments during the loading process?

@navybofus said: So, is there no way to bypass the empty constructor? Or tell certain objects to pass arguments during the loading process?
Clearly the t0neg0d API is not meant to be serialized. Trying to force it to work isn't going to help much because the object fields are not actually persisted in the file.

Okay then would it be wise for me to only use the InteractiveNode objects for in-game representation(the model) and then save the userData some other way?

Edit: I guess maybe an example might help to understand what I’m saving.

I have a mound of soil Object. Each object has four data keys: isWatered boolean, isSeeded boolean, Seed_Type String and TimeUntilGrown float. Since I need this data to persist after the game is closed, I’m trying to save the values.

Edit 2: I’ve created an empty constructor in the InteractiveNode abstract class so I could do so in it’s children (I know this won’t work because of the required ElementManager, but I’m just testing). Now, even though the save file is on the hard disk it’s not being recognized. I’m getting a AssetNotFoundException. Which I will later catch because on the initial play there won’t be one anyway.

So, wait… you are saving the UI classes just so that your game data gets saved? Yeah, you are right that you don’t want to do that.

Save your game data if you want to save your game data… no reason to include a whole user interface hierarchy in that. Amazingly wasteful, really.

@pspeed said: So, wait... you are saving the UI classes just so that your game data gets saved? Yeah, you are right that you don't want to do that.

Save your game data if you want to save your game data… no reason to include a whole user interface hierarchy in that. Amazingly wasteful, really.

I agree. As I’m still new to jMonkey(only a month under my belt) I learn more and more each day, however when I originally started trying to implement save/load functionality I thought that only the userData was saved, not the entire object. I only showed the hierarchy above to visualize that Savable was being passed down to my objects.

I’m still stuck though. I’m not sure what’s wrong with my code, but if I’m still having problems tomorrow I’ll post it to see if I’m just doing it all wrong. I find a lot of questions, but not a lot of answers on this topic, which leads my to believe that it’s simple and I’m just not getting it :slight_smile:

You can just recreate your “other” classes based on whatever data you really need to persist. So in a savable you could save things like UI window positions and then you just recreate the UI like you would the first time and use these window positions. Same for other classes.

I’m very grateful for all of the quick replies! I’ve created a small test project so I could get to the bare essentials of saving and loading and I’ve got a much better grasp on it now.

Thanks again,
Navybofus