|
-
Aug 26th, 2001, 08:26 PM
#1
Thread Starter
Addicted Member
Or you can save the data in a binary file. Each character could have it's variables in a UDT.
Code:
' Type for storing character's data
Public Type Character_Values
cvLife As Integer
cvHealth As Integer
cvName As String
' etc., etc.
End Type
' Array of characters
Public udtChar() As Character_Values
Public Sub SaveGame()
' Save a game to a file
Dim ff As Integer, lNum As Long
ff = FreeFile
Open App.Path & "\game.dat" For Binary As #ff
' How many characters are there?
lNum = UBound(udtChar)
Put #ff, , lNum
' Save data
Put #ff, , udtChar()
Close #ff
End Sub
Public Sub LoadGame()
' Load a game from a file
Dim ff As Integer, lNum As Long
ff = FreeFile
Open App.Path & "\game.dat" For Binary As #ff
' # of chars...
Get #ff, , lNum
' Resize arrary and load data
Redim udtChar(lNum)
Get #ff, , udtChar()
Close #ff
End Sub
-
Aug 27th, 2001, 12:13 PM
#2
Frenzied Member
If you saved your file like:
VB Code:
Open "C:\Game\Save1.sav" For Binary As #1
Put #1,,Character1Life 'NOTE: That's 2 commas (,) I used!!!
Put #1,,Character1Name
Put #1,,Character1Class
'...
Close #1
...you could load it like this:
VB Code:
Open "C:\Game\Save1.sav" For Binary As #1
Get #1,,Character1Life
Get #1,,Character1Name
Get #1,,Character1Class
'...
Close #1
Get it?
-
Aug 27th, 2001, 03:24 PM
#3
Fanatic Member
I would go for the UDT code, it's much easier to change what variables are stored in the file (read: add one line of code without updating the LoadGame and SaveGame functions every time)...
This question was asked a lot, so I created this tutorial: UDT's and Binary File Access, it might be of some use to you...
Teaudirenopossum.Musasapientumfixaestinaure.
(I can't hear you. There's a banana in my ear)
-
Aug 27th, 2001, 05:37 PM
#4
Frenzied Member
HEy if I got you right meatlguy than the only right thing would be a textfile because there you could load only one line, but I think the binary way with loading all the data Jotaf showed is the best, just use UDTs so you don'T have to write the same crap 100000 times.
Sanity is a full time job
Puh das war harter Stoff!
-
Aug 28th, 2001, 10:09 AM
#5
Frenzied Member
Yeah, well, he has only 3 posts so he's [probably] a begginer in VB. I tried to keep it as simple as possible
-
Aug 28th, 2001, 11:03 AM
#6
-
Aug 28th, 2001, 11:38 AM
#7
Frenzied Member
Well me too, hehe, I almost had forgotten that
-
Aug 28th, 2001, 11:43 AM
#8
Fanatic Member
But anyways, I do recommend the UDT technique. Even if you've never saved something to files before, it's not very difficult to use this technique (it might even be easier than manual loading/saving every variable, and hey, there's always my tutorial and this forum ) and it's a lot more organized way of coding...
Teaudirenopossum.Musasapientumfixaestinaure.
(I can't hear you. There's a banana in my ear)
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
|