VB .Net 2008 Save and Load system

  • (2 Pages)
  • +
  • 1
  • 2

25 Replies - 5576 Views - Last Post: 04 February 2011 - 03:08 PM Rate Topic: -----

#1 xweetok59  Icon User is offline

  • New D.I.C Head

Reputation: -16
  • View blog
  • Posts: 45
  • Joined: 23-June 10

VB .Net 2008 Save and Load system

Posted 04 February 2011 - 10:58 AM

Now I'm making a kinda game in vb .Net 2008. It's a game that continues for a long time and isn't done in a hour, so it is pretty annoying that if the player re-opens the game he has to do everything over again. So, does anybody know how I can make a save/load system? Like that on the first form of the game there is a "Save" and "Load" button. If the player presses the "Save" button, the program automatically saves the progress of the player in a file somewhere on the harddisk of the player, and if the player presses "Load", the program automatically loads the file he saved, so the player doesn't have to start all over again.

Is This A Good Question/Topic? 0
  • +

Replies To: VB .Net 2008 Save and Load system

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9201
  • View blog
  • Posts: 34,575
  • Joined: 12-June 08

Re: VB .Net 2008 Save and Load system

Posted 04 February 2011 - 11:03 AM

It all depends what you are saving. Push everything into an XML format, use 'stream writer' to put that to a file, and use 'stream reader' to get it back on a load.
Was This Post Helpful? 0
  • +
  • -

#3 xweetok59  Icon User is offline

  • New D.I.C Head

Reputation: -16
  • View blog
  • Posts: 45
  • Joined: 23-June 10

Re: VB .Net 2008 Save and Load system

Posted 04 February 2011 - 11:13 AM

View Postmodi123_1, on 04 February 2011 - 11:03 AM, said:

It all depends what you are saving. Push everything into an XML format, use 'stream writer' to put that to a file, and use 'stream reader' to get it back on a load.

Uhm well, I'm not so good in Vb .Net coding, so I don't really know how to do something like that. Do you maybe have a tutorial or something to do something like that?
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9201
  • View blog
  • Posts: 34,575
  • Joined: 12-June 08

Re: VB .Net 2008 Save and Load system

Posted 04 February 2011 - 11:17 AM

Yup... google 'vb.net xml streamreader'.

and you find: http://support.microsoft.com/kb/301228
Was This Post Helpful? 0
  • +
  • -

#5 xweetok59  Icon User is offline

  • New D.I.C Head

Reputation: -16
  • View blog
  • Posts: 45
  • Joined: 23-June 10

Re: VB .Net 2008 Save and Load system

Posted 04 February 2011 - 11:47 AM

View Postmodi123_1, on 04 February 2011 - 11:17 AM, said:

Yup... google 'vb.net xml streamreader'.

and you find: http://support.microsoft.com/kb/301228

I looked through some more of these tutorials, but I just don't understand it...
Was This Post Helpful? 0
  • +
  • -

#6 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9201
  • View blog
  • Posts: 34,575
  • Joined: 12-June 08

Re: VB .Net 2008 Save and Load system

Posted 04 February 2011 - 12:00 PM

I can't help your understanding, and I am not going to write the code for you. I can provide the format you would want to keep near.

FYI if you go the XML route use the XML writer... if you are not using xml stick with 'streamreader/writer'.

1. Make an XML object.
2. Put your data (and create nodes for each) into that xml object.
3. Create a XmlTextWriter object.
4. Using your XmlTextWriter write the string of your xml object to your location.
5. Make sure you can use an xmltextreader to get your xml back into an xml object.
6. Navigate xml object to get your data back out.


MSDN on Xml reader.
http://msdn.microsof...v=vs.71%29.aspx

MSDN on stream reader.
http://msdn.microsof...reamreader.aspx
http://msdn.microsof...y/6ka1wd3w.aspx
http://msdn.microsof...y/db5x7c0d.aspx
Was This Post Helpful? 0
  • +
  • -

#7 Guest_Jim*


Reputation:

Re: VB .Net 2008 Save and Load system

Posted 04 February 2011 - 12:10 PM

XML rather seems like another layer of complexity to me. I know there is value in learning XML, but I have gotten along without it for the last 13 years (XML was developed in '98).

There are other ways to do this. . . .

  • You can use Ini files if you're not saving particularly complex information.
  • You could read and write a text file of your own design
  • If you've got a nice object structure, you may want to add a couple of methods that can save your objects to a file and repopulate them from a file.


I've used the 3rd method in a few different projects over the years. I've never had a problem with losing data, but I can see where an XML file might be easier to debug if a file became corrupted for some reason.

Jim
Was This Post Helpful? 0

#8 Guest_Jim*


Reputation:

Re: VB .Net 2008 Save and Load system

Posted 04 February 2011 - 12:19 PM

Here's a link that might be helpful: Object Serialization in the .NET Framework

Jim
Was This Post Helpful? 0

#9 xweetok59  Icon User is offline

  • New D.I.C Head

Reputation: -16
  • View blog
  • Posts: 45
  • Joined: 23-June 10

Re: VB .Net 2008 Save and Load system

Posted 04 February 2011 - 01:03 PM

Isn't it possible to do like that the program writes the .xml file and loads it instead of only loading it, but not making it?
Was This Post Helpful? 0
  • +
  • -

#10 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9201
  • View blog
  • Posts: 34,575
  • Joined: 12-June 08

Re: VB .Net 2008 Save and Load system

Posted 04 February 2011 - 01:10 PM

Yes.. you have to CREATE the xml first.. fill it with your data.. and then use the XML writer to write it. My guess is your data is scattered over different variables, right? Then you have to collect them up, make nodes, and fill them.
Was This Post Helpful? 0
  • +
  • -

#11 xweetok59  Icon User is offline

  • New D.I.C Head

Reputation: -16
  • View blog
  • Posts: 45
  • Joined: 23-June 10

Re: VB .Net 2008 Save and Load system

Posted 04 February 2011 - 01:12 PM

View Postmodi123_1, on 04 February 2011 - 01:10 PM, said:

Yes.. you have to CREATE the xml first.. fill it with your data.. and then use the XML writer to write it. My guess is your data is scattered over different variables, right? Then you have to collect them up, make nodes, and fill them.

What data...?
Was This Post Helpful? 0
  • +
  • -

#12 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9201
  • View blog
  • Posts: 34,575
  • Joined: 12-June 08

Re: VB .Net 2008 Save and Load system

Posted 04 February 2011 - 01:13 PM

How ever you determine "the progress of the player".
Was This Post Helpful? 0
  • +
  • -

#13 xweetok59  Icon User is offline

  • New D.I.C Head

Reputation: -16
  • View blog
  • Posts: 45
  • Joined: 23-June 10

Re: VB .Net 2008 Save and Load system

Posted 04 February 2011 - 01:17 PM

View Postmodi123_1, on 04 February 2011 - 01:13 PM, said:

How ever you determine "the progress of the player".

Actually, what i wanted to do is. Look, like, the player plays the game. But when he stops playing and closes the game, he loses everything he did before and has to start from the beginning again if he opens the game up again. What I want to do is make a "Save" button, that saves everything the player did in a file, and when the player closes the game, he can re-open the saved file by pressing "Load", so he doesn't have to start from the beginning again.
Was This Post Helpful? 0
  • +
  • -

#14 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9201
  • View blog
  • Posts: 34,575
  • Joined: 12-June 08

Re: VB .Net 2008 Save and Load system

Posted 04 February 2011 - 01:24 PM

Yeah, I got that. I have no idea what your game is, nor how you are going to determine what "everything the player did" is. I mean does your game have states? It must track SOME sort of information, right? Information that you can pull out of variables.

Maybe it would be helpful if I knew what your game already is doing?
Was This Post Helpful? 0
  • +
  • -

#15 xweetok59  Icon User is offline

  • New D.I.C Head

Reputation: -16
  • View blog
  • Posts: 45
  • Joined: 23-June 10

Re: VB .Net 2008 Save and Load system

Posted 04 February 2011 - 01:28 PM

View Postmodi123_1, on 04 February 2011 - 01:24 PM, said:

Yeah, I got that. I have no idea what your game is, nor how you are going to determine what "everything the player did" is. I mean does your game have states? It must track SOME sort of information, right? Information that you can pull out of variables.

Maybe it would be helpful if I knew what your game already is doing?

It's a game where you have money. You have to buy materials and a own shop and factory, produce goods and sell them to earn more money. It has 4 forms and 1 module file where I declare the strings. With all the player did I mean like that he can save the amount of money he has, and if he bought a shop and... Well, actually, all the strings... There are also timers in my game, used for the producing goods part.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2