Click to See Complete Forum and Search --> : Saving Info
DarkMoose
Oct 7th, 2000, 09:48 AM
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...
oetje
Oct 7th, 2000, 10:29 AM
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:
'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:
WriteSaveGame
To Open:
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.
DarkMoose
Oct 7th, 2000, 11:36 AM
Ok, I think that will do it! Thnx a lot.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.