|
-
Jun 16th, 2001, 05:22 PM
#1
Thread Starter
New Member
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.
-
Jun 17th, 2001, 07:53 AM
#2
Member
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.
-
Jun 18th, 2001, 03:07 AM
#3
Fanatic Member
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)
-
Jun 18th, 2001, 04:30 AM
#4
PowerPoster
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
-
Jun 18th, 2001, 06:36 AM
#5
CAnt we just create a new "extension" like .sav and put stuff on it like in Diablo or other game like that ?
-
Jun 18th, 2001, 08:07 AM
#6
PowerPoster
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|