Results 1 to 8 of 8

Thread: Load / Save Game Info

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2009
    Posts
    8

    Load / Save Game Info

    Im making a simple game but I have problem with getting a coda were i can save and load my information to a database or a file, i need to save several integer files and string files

    Code:
    Dim Level As Integer, XP As Integer, 
    dim PlName As String, Money As Integer, Mana As Integer, Life As Integer
    This is what who needs to be saved, it will later on be a Online game how must the data be saved then?

  2. #2
    New Member
    Join Date
    Sep 2008
    Posts
    4

    Re: Load / Save Game Info

    You could make it a .csv file, or wouldn't that work?

  3. #3

    Thread Starter
    New Member
    Join Date
    Jan 2009
    Posts
    8

    Re: Load / Save Game Info

    I really dont know :P Have no idea how a save function works... dont know any code to save anything almost :P If you do please share your knowledge

  4. #4
    Hyperactive Member
    Join Date
    Mar 2008
    Location
    Zeist, The Netherlands
    Posts
    266

    Re: Load / Save Game Info

    You can create a StreamWriter object, it's pretty simple:
    http://msdn.microsoft.com/en-us/library/6ka1wd3w.aspx

  5. #5
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Smile Re: Load / Save Game Info

    VB.NET: Use this.
    Code Code:
    1. Dim fs As New IO.FileStream("gamesave.bin",IO.FileMode.Write,IO.FileAccess.Read)
    2. Dim wr As New IO.StreamWriter(fs)
    3. wr.Write(level.toString & ",")
    4. wr.Write(XP.toString & ",")
    5. wr.Write(life.toString & ",")
    6. wr.Write(mana.toString & ",")
    7. wr.Write(money.toString & ",")
    8. wr.Write(PLName)
    9. wr.Close()
    10. fs.Close()

    VB6: Roughly this, but I don't use VB6.
    Code Code:
    1. Open "gamesave.bin" For Output As #File
    2. Write #File, Str(level) & ","
    3. 'etc. for all of them.
    4. Close #File

    I'll write how to read the data and explain it later, I don't have much time

  6. #6
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Re: Load / Save Game Info

    Ok, so. You have the IO.FileStream and IO.StreamWriter/Reader objects, explore their constructors and you should get a pretty good idea on how to initialize those objects. You should then explore the StreamWriter/Reader's methods. Just remember: once you're done with the objects, run their Close() methods, not dispose. You must run Close() for all of the file-related objects (unless they don't have a Close() method). If you don't, you could have some funny errors.

  7. #7
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    Re: Load / Save Game Info

    Perhaps writing a game is beyond your grasp at the moment.

    I do not mean to offend, however if you are having troubles reading and writing files (which is around chapter 2 in any programming book / tutorial), then you will certainly have trouble with both graphics, and network communications.

    chem

    Visual Studio 6, Visual Studio.NET 2005, MASM

  8. #8
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Re: Load / Save Game Info

    Hmm... he's right.
    I suggest you just go to the library and get a big VB.NET book that will tell you all you need to know. (That's how I learned VB.)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width