Results 1 to 5 of 5

Thread: Game Question

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2001
    Posts
    10

    Question Game Question

    I was wondering if anyone knows the code to implement a save and load feature into a game, plz post a snippet of code or detailed example, i know a fair amount but adviously not that much.

    Please don't make it some incredibly hard small code, id'd rather have a huge easy to understand code.

    Gorf

  2. #2
    Fanatic Member PsychoMark's Avatar
    Join Date
    Feb 2001
    Location
    Netherlands
    Posts
    540
    Teaudirenopossum.Musasapientumfixaestinaure.
    (I can't hear you. There's a banana in my ear)

  3. #3
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    Well you basically just have to know what you want to load/save.
    Here is a sample :

    Code:
    Option Explicit
    
    'Code assumes save.game is in following format :
    '
    'name           =Blah Blah Blah
    'age            =334
    'TotalKills     =3493
    'ExperienceLevel=324
    '
    
    Private thePlayer As playerType
    Private Type playerType
        Name As String
        Age As Integer
        TotalKills As Long
        ExperienceLevel As Long
        'and others if applicable
    End Type
    
    Private Sub LoadGame()
        Dim varTemp As String
        Open App.Path & "\game.save" For Input As #1
            Do Until EOF(1)
                DoEvents
                Line Input #1, varTemp
                Select Case Left(varTemp, 16)
                    Case "name           =":
                        thePlayer.Name = Mid(varTemp, 17)
                    Case "age            =":
                        thePlayer.Age = Mid(varTemp, 17)
                    Case "TotalKills     =":
                        thePlayer.TotalKills = Mid(varTemp, 17)
                    Case "ExperienceLevel=":
                        thePlayer.ExperienceLevel = Mid(varTemp, 17)
                End Select
            Loop
        Close #1
        MsgBox "Game Loaded !"
    End Sub
    
    Private Sub SaveGame()
        Open App.Path & "\game.save" For Output As #1
            With thePlayer
                Print #1, "name           =" & .Name
                Print #1, "age            =" & .Age
                Print #1, "TotalKills     =" & .TotalKills
                Print #1, "ExperienceLevel=" & .ExperienceLevel
            End With
        Close #1
    End Sub
    Last edited by plenderj; Apr 26th, 2001 at 04:10 AM.
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  4. #4
    Fanatic Member PsychoMark's Avatar
    Join Date
    Feb 2001
    Location
    Netherlands
    Posts
    540
    plenderj, if you've followed the link you'll notice that I'm using the UDT too, but instead of manually writing and reading each line, I'm writing the whole UDT at once, which is much easier...
    Teaudirenopossum.Musasapientumfixaestinaure.
    (I can't hear you. There's a banana in my ear)

  5. #5
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    Sorry, It took me so long to write the post I had never read yours
    Anyway yeah I had never actually use UDTs like that before ... I never even knew you could.

    Well we all learn things
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

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