|
-
Mar 24th, 2012, 03:12 PM
#1
Thread Starter
Hyperactive Member
Serialization Question
I spend my spare time trying to create a football game in VB.NET. I have a save game file saved using serialization which I am using to test code. This file contains all the elements of gameplay (stored plays, games, options, etc...) I create this file in the software itself using the code I created; I put a lot of work into this save game file and I would like to continue using it.
However, I discovered I need to add a couple member variables to the class from which the saved object is derived (object is called m_League, class is ClLeague). Any time I've altered ClLeague my old saved games don't load anymore because the new m_League object does not match the old m_League object. I have to start a new game and create m_League from scratch which wastes a lot of time.
This must pop up in with the professionals out there who write patches for software and need the users old saved files to continue working. Is there any trick to this situation or do I have to just accept it?
Thanks!
Intermediate Level Programmer Extraordinaire 
-
Mar 24th, 2012, 03:48 PM
#2
Re: Serialization Question
I'm assuming you are using Binary Serialization. Use XML Serialization instead, which is usually not affected by the changes to the class (unless of course a lot has changed to make that information unusable)
-
Mar 24th, 2012, 06:12 PM
#3
Re: Serialization Question
There would be a weird workaround, which would be to make a converter. You would have to retain the old class and the new class as two separate things with a method to convert one to the other. You would then deserialize the old class, run the method, then serialize the new class. This would require more discipline than anything else. If your class was in a dll, it probably wouldn't be particularly difficult, but it would be a pain if you had it in the main program.
PS: While XML serialization might solve the problem, it isn't exactly a replacement. If you use that, you have to accept the XML nature of the data, which means files that are easily read and altered by anybody unless you encrypt them, and they will be relatively HUGE. Furthermore, I seem to remember that there were some real limitations to XML serialization, though I don't remember what they were. Some types of collections wouldn't serialize correctly.
My usual boring signature: Nothing
 
-
Mar 24th, 2012, 07:53 PM
#4
Thread Starter
Hyperactive Member
Re: Serialization Question
Very clever "converter" idea!. I'll have to think about what's better: just to spend time recreating stuff in my game or making a better long term solution by trying your idea.
Also, XML serialization is not the answer for my situation for the reasons you stated Shaggy Hiker.
Thank you both for your ideas. I'll let this thread run another day and then mark it Solved.
Intermediate Level Programmer Extraordinaire 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|