Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Save Game


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
7 replies to this topic

#1 Saint Squireen   Members   -  Reputation: 181

Like
1Likes
Like

Posted 20 July 2012 - 05:07 PM

(Straight to the point) I want to save health, level, experience, coins whenever needed and then close the application and then restart the application and recall health, level, experience, coins whenever needed.

Is there any real good ways of doing this? A google search has turned up nothing useful and I could use some help.

~Saint Squireen

Sponsor:

#2 Radikalizm   Crossbones+   -  Reputation: 2925

Like
3Likes
Like

Posted 20 July 2012 - 05:14 PM

The technique you're looking for is called serialization. Serialization is the process of writing out data from your application to a file (or any other external medium) so that it can be loaded back in at a later time.
Depending on the language you're using you could already have the tools to do this quite easily. A lot of managed languages already provide tools for easily writing out the contents of your classes or structures to binary files, text files, xml files, etc.

I gets all your texture budgets!


#3 Saint Squireen   Members   -  Reputation: 181

Like
0Likes
Like

Posted 20 July 2012 - 06:49 PM

i am currently using C++.

~Saint Squireen

#4 Radikalizm   Crossbones+   -  Reputation: 2925

Like
5Likes
Like

Posted 20 July 2012 - 07:04 PM

i am currently using C++.


C++ does not provide any built-in tools for serializing classes, so you'll have to provide these yourself.
A common way of doing this is to create a Serializable class which you use as a base for all your classes you want to be able to serialize. This class could contain a pure virtual function called serialize which takes a filename as input. You then implement this function for every child class, and you write out the all the data for your class to the file with the given filename individually using the the normal C++ file IO mechanisms.
If you want to export your classes as text data you'll have to make sure you first of all create valid string representations of your class members.
The only thing you have to do then is reverse the process described above so you can construct or populate classes from file data. You could use a factory pattern to achieve this this for example.

If you want to elaborate on this technique some more you could build an attribute system where you first convert your class data to a set of attributes which you can then export any way you want with a generic attribute serializer. This would also allow you to collect all the data you'd want to save before doing any actual exporting.


Another way I've seen serialization done is to overload the stream operators for your class so you can export your class data to a stream. I haven't made any extensive use of this approach though, so I couldn't tell you any up- or downsides of this technique.

I gets all your texture budgets!


#5 Saint Squireen   Members   -  Reputation: 181

Like
0Likes
Like

Posted 20 July 2012 - 07:17 PM

ok thanks for the insight :)

~Saint Squireen

#6 Radikalizm   Crossbones+   -  Reputation: 2925

Like
3Likes
Like

Posted 20 July 2012 - 07:24 PM

Another thing I forgot to add:

If you just have to write out a small amount of values then a full serialization system might be overkill, you can always just use the file IO systems provided by C++ to write your values out to a binary or text file. An actual serialization system should come into play the moment where you find yourself needing to export/import entire class states.

I gets all your texture budgets!


#7 Matt-D   Crossbones+   -  Reputation: 1467

Like
0Likes
Like

Posted 20 July 2012 - 08:25 PM

See:
http://en.wikipedia.org/wiki/Serialization#C_and_C.2B.2B
http://stackoverflow.com/questions/234724/how-to-serialize-in-c
http://www.parashift.com/c++-faq-lite/serialization.html
http://www.ocoudert.com/blog/2011/07/09/a-practical-guide-to-c-serialization/
http://gamedev.stackexchange.com/questions/2269/what-are-good-solutions-for-serialization-in-c

#8 Saint Squireen   Members   -  Reputation: 181

Like
0Likes
Like

Posted 21 July 2012 - 09:05 AM

thanks guys!! :)

~Saint Squireen




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS