Results 1 to 6 of 6

Thread: Load/Save a game

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2001
    Posts
    5

    Red face Load/Save a game

    Hi there!I'm making the Hanoi game on vb,but I don't know how can I make a procedure so that the player can save his game and load it at anytime.I'll appreciate if anyone can help me.Thanks.

  2. #2
    Member FinnPanther's Avatar
    Join Date
    Jun 2001
    Location
    Finland
    Posts
    53
    Hmm... what kind of game it is?

    I think the easiest way to make a save is something like this:


    'cmdSave.Click

    open "d:\path\save.ext" for output as #1

    print #1, strVar1
    print #1, strVar2
    print #1, strVar3
    print #1, intPlayerXPos
    print #1, intPlayerYPos
    'use the write # statement for boolean values

    close #1

    'cmdLoad.Click

    open "d:\path\save.ext" for input as #1

    line input #1, strVar1 'not sure about this, check the msdn help
    line input #1, strVar2
    line input #1, strVar3
    line input #1, intPlayerXPos
    line input #1, intPlayerYPos

    close #1


    If you'd like, I could put here a save/load procedure from a game I'm working on... It works like above, but in addition it crypts the save file so it can't be edited

    BTW: Again I'm sorry I can't use that vbcode function here...
    Have to learn someday.
    -Panther

    Panther's HQ

  3. #3
    Fanatic Member PsychoMark's Avatar
    Join Date
    Feb 2001
    Location
    Netherlands
    Posts
    540
    http://psprogramming.multimania.com/...udtbinary.html


    That is, in my opinion, the easiest yet most flexible way of loading and saving game data.
    Teaudirenopossum.Musasapientumfixaestinaure.
    (I can't hear you. There's a banana in my ear)

  4. #4
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    Yep. Heres some sample code: (use in a module)

    Code:
    'Types
        Type tREPLACE_NAME
            Value1 As Long
            Value2 As String
            Value3 As Integer
        End Type
        
    'Variables
        Public REPLACE_NAMECount As Long
        Public REPLACE_NAME() As tREPLACE_NAME
    
    Sub LoadData(iFileName As String)
        Dim FileNumber As Integer
    
        'Reset
        Reset
        
        'Verify filename
        If Not Exists(iFileName) Then
            'Error: File not found
            
            Exit Sub
        End If
    
        'Read file
        FileNumber = FreeFile
        Open iFileName For Binary As FileNumber
            'Count
            Get FileNumber, , REPLACE_NAMECount
            
            'Data
            If REPLACE_NAMECount > -1 Then
                ReDim REPLACE_NAME(REPLACE_NAMECount)
                
                Get FileNumber, , REPLACE_NAME
            End If
        Close FileNumber
    End Sub
    
    Sub SaveData(iFileName As String)
        Dim FileNumber As Integer
    
        'Delete file
        If Exists(iFileName) Then: Kill iFileName
    
        'Write file
        FileNumber = FreeFile
        Open iFileName For Binary As FileNumber
            'Count
            Put FileNumber, , REPLACE_NAMECount
            
            'Data
            If REPLACE_NAMECount > -1 Then
                Put FileNumber, , REPLACE_NAME
            End If
        Close FileNumber
    End Sub

  5. #5
    DaoK
    Guest
    CAnt we just create a new "extension" like .sav and put stuff on it like in Diablo or other game like that ?

  6. #6
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    What's the problem?

    Use my function like this:

    Code:
    SaveData "test.sav"
    Extensions do say nothing about the file contents/format. In windows the header is important but if you're making savegames you can just use a function like mine and put the data in... you can chose any extension you want, even .exe .com .txt -" .savegame of my file" - whatever

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