Results 1 to 8 of 8

Thread: Saving, PLEASE HELP!!!

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Location
    Croatia
    Posts
    200
    Or you can save the data in a binary file. Each character could have it's variables in a UDT.

    Code:
    ' Type for storing character's data
    Public Type Character_Values
            cvLife As Integer
            cvHealth As Integer
            cvName As String
            ' etc., etc.
    End Type
    ' Array of characters
    Public udtChar() As Character_Values
    
    
    Public Sub SaveGame()
    ' Save a game to a file
    
    Dim ff As Integer, lNum As Long
    ff = FreeFile
    
    Open App.Path & "\game.dat" For Binary As #ff
            ' How many characters are there?
            lNum = UBound(udtChar)
            Put #ff, , lNum
            ' Save data
            Put #ff, , udtChar()
    Close #ff
    End Sub
    
    Public Sub LoadGame()
    ' Load a game from a file
    
    Dim ff As Integer, lNum As Long
    ff = FreeFile
    
    Open App.Path & "\game.dat" For Binary As #ff
            ' # of chars...
            Get #ff, , lNum
            ' Resize arrary and load data
            Redim udtChar(lNum)
            Get #ff, , udtChar()
    Close #ff
    End Sub

  2. #2
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    If you saved your file like:

    VB Code:
    1. Open "C:\Game\Save1.sav" For Binary As #1
    2.  
    3. Put #1,,Character1Life 'NOTE: That's 2 commas (,) I used!!!
    4. Put #1,,Character1Name
    5. Put #1,,Character1Class
    6.  
    7. '...
    8.  
    9. Close #1

    ...you could load it like this:

    VB Code:
    1. Open "C:\Game\Save1.sav" For Binary As #1
    2.  
    3. Get #1,,Character1Life
    4. Get #1,,Character1Name
    5. Get #1,,Character1Class
    6.  
    7. '...
    8.  
    9. Close #1

    Get it?
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

  3. #3
    Fanatic Member PsychoMark's Avatar
    Join Date
    Feb 2001
    Location
    Netherlands
    Posts
    540
    I would go for the UDT code, it's much easier to change what variables are stored in the file (read: add one line of code without updating the LoadGame and SaveGame functions every time)...

    This question was asked a lot, so I created this tutorial: UDT's and Binary File Access, it might be of some use to you...
    Teaudirenopossum.Musasapientumfixaestinaure.
    (I can't hear you. There's a banana in my ear)

  4. #4
    Frenzied Member /\/\isanThr0p's Avatar
    Join Date
    Jul 2000
    Location
    They can't stop us! We're on a misson from God.
    Posts
    1,181
    HEy if I got you right meatlguy than the only right thing would be a textfile because there you could load only one line, but I think the binary way with loading all the data Jotaf showed is the best, just use UDTs so you don'T have to write the same crap 100000 times.
    Sanity is a full time job

    Puh das war harter Stoff!

  5. #5
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    Yeah, well, he has only 3 posts so he's [probably] a begginer in VB. I tried to keep it as simple as possible
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

  6. #6
    Fanatic Member PsychoMark's Avatar
    Join Date
    Feb 2001
    Location
    Netherlands
    Posts
    540
    I was an experienced programmer by the time I had 3 posts here (yes, I did have a life before this forum )
    Teaudirenopossum.Musasapientumfixaestinaure.
    (I can't hear you. There's a banana in my ear)

  7. #7
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    Well me too, hehe, I almost had forgotten that
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

  8. #8
    Fanatic Member PsychoMark's Avatar
    Join Date
    Feb 2001
    Location
    Netherlands
    Posts
    540
    But anyways, I do recommend the UDT technique. Even if you've never saved something to files before, it's not very difficult to use this technique (it might even be easier than manual loading/saving every variable, and hey, there's always my tutorial and this forum ) and it's a lot more organized way of coding...
    Teaudirenopossum.Musasapientumfixaestinaure.
    (I can't hear you. There's a banana in my ear)

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