Results 1 to 3 of 3

Thread: Saving Info

  1. #1

    Thread Starter
    Addicted Member DarkMoose's Avatar
    Join Date
    Jul 2000
    Location
    in a box
    Posts
    185
    Does anyone know a way to save a game file for an rpg? Like, where the player is at in the game and their current stats. You know, just like saving yer game in Zelda. I don't want to save anything to a text file cuz then anyone could just change it...
    To understand recursion, one must first understand the concept of recursion.

  2. #2
    Fanatic Member
    Join Date
    Feb 2000
    Location
    The Netherlands
    Posts
    715
    Ok, this is a small example. You can use a user defined type. Something like this.
    Put this code in the general declarations section of the form:
    Code:
    'the user defined type
    Private Type GameInfo
        Xpos As Long
        Ypos As Long
        Health As Integer
    End Type
    
    Private Sub WriteSaveGame()
        Dim TheData As GameInfo 'the game info
        
        'set the game info
        TheData.Xpos = 193
        TheData.Ypos = 764
        TheData.Health = 69
    
        'write the game info
        Open App.Path & "\savegame.dat" For Binary As #1
            Put #1,,TheData
        Close #1
    End Sub
    
    Private Function ReadSaveGame() As GameInfo
        Dim TheData As GameInfo 'temporary var
        
        'read the data
        Open App.Path & "\savegame.dat" For Binary As #1
            Get #1,,TheData
        Close #1
        
        'return the data
        ReadSaveGame = TheData
    End Function
    Now your form has 2 functions, you can use them like this.

    To Save:
    Code:
        WriteSaveGame
    To Open:
    Code:
        Dim TheData As GameInfo
        
        'read the file
        TheData = ReadSaveGame
    
        'put the data in the debug window
        Debug.Print TheData.Xpos
        Debug.Print TheData.Ypos
        Debug.Print TheData.Health
    I hope this helped you.
    Oetje
    [email protected]
    93606776
    Visual Basic 6, Windows 2000

    Never pet a burning dog

  3. #3

    Thread Starter
    Addicted Member DarkMoose's Avatar
    Join Date
    Jul 2000
    Location
    in a box
    Posts
    185
    Ok, I think that will do it! Thnx a lot.
    To understand recursion, one must first understand the concept of recursion.

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