|
-
Apr 25th, 2001, 09:28 PM
#1
Thread Starter
New Member
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
-
Apr 26th, 2001, 03:57 AM
#2
Fanatic Member
Teaudirenopossum.Musasapientumfixaestinaure.
(I can't hear you. There's a banana in my ear)
-
Apr 26th, 2001, 04:06 AM
#3
Retired VBF Adm1nistrator
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]
-
Apr 26th, 2001, 04:09 AM
#4
Fanatic Member
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)
-
Apr 26th, 2001, 04:13 AM
#5
Retired VBF Adm1nistrator
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|