Save/Load

Started by
8 comments, last by MicroProgrammer 21 years ago
Where can I find out how to have a save\load option in my VB6 game. I want to have the game to be able to save and laod. I need a code and\or website(s)
Advertisement
Basically, you just want to be able to let the player save/load a given "state" of your game. For example, say that you are making a tic-tac-toe game. Each of the nine squares will either be empty, or have an X or an O. This data would be your normal game state data, which you would probably store in an array. All you need to do to have the player save his/her game would be to write this array to a file. When the player loads his/her game, the file is opened and the array is read back into the game, and Viola! The previous game state has been recreated, and the player may continue his game.

As for tutorials/code on the net, you will want to learn about file I/O (input/output).

Good luck!

-Mike
Yeah but i have no clue how to do that. Do u?
Dump all of the variables to a file, and then write some code to restore them.

--------------------------------------------
Optimus Prime: Private Investigator!

Oscar Mike Foxtrot Golf! Whiskey Tango Foxtrot"
Well Mr Saturn, if that IS your real name...
With love, AnonymousPosterChild
Okay that does help a little. Thx But do u have a code for VB. A code compatible with Visual Basic 6.0?
I''m not sure of what code you have, or what game you''re making, but here is a simple example.

Dim PlayerX as long, PlayerY as long

Public Sub SaveGame
open app.path & "\SaveGame.txt" for output as #1
print #1, PlayerX ''Write out our PlayerX
print #1, PlayerY ''Write out our PlayerY
close #1
End Sub


Public Sub LoadGame
On Error Goto FileNotFound ''On error, jump to bottom, and skip loading!
open app.path & "\SaveGame.txt" for input as #1
input #1, PlayerX ''Read our PlayerX in
input #1, PlayerY ''Read our PlayerY in
close #1
Exit Sub ''Exit sub, so we don''t display our not found message
FileNotFound: ''woops, nothing found
MsgBox "Load game was not found!"
End Sub


Hope this helps, of course, you would write/read whatever variables you needed to restore your games state.

If you have any further questions, or need more information or help, you can contact me directly at: Ready4Dis@aol.com, Ready4Dis@piqsoftware.com, or on AIM (CrazyGuy4Eva) or on msn instant messenger (Ready4Dis_1@hotmail.com).
Just wanted to mention... app.path stores the current path that the game is running from, so I used that in the load/save functions so that it saves in the games directory, and not just some random place on the hard drive . If you''ve got any more questions, feel free to ask on gamedev, or contact me directly (I''m the AP above, don''t feel like logging in).
Hey, is there a way that it will save the text from a text box to a txt and than bring all the info back to the right textboxes?
Dim PlayerX as long, PlayerY as long

Public Sub SaveGame
open app.path & "\SaveGame.txt" for output as #1
print #1, TextBox1.text
close #1
End Sub


Public Sub LoadGame
On Error Goto FileNotFound ''On error, jump to bottom, and skip loading!
open app.path & "\SaveGame.txt" for input as #1
input #1, TextBox1.text ''Read our PlayerY in
close #1
Exit Sub ''Exit sub, so we don''t display our not found message
FileNotFound: ''woops, nothing found
MsgBox "Load game was not found!"
End Sub
I teleported home one night; With Ron and Sid and Meg; Ron stole Meggie's heart away; And I got Sydney's leg. <> I'm blogging, emo style
This wont work. It comes up with a error. I want it so i write Hi in textbox1 and save it. Then i change the word and press laod it loads Hi and puts it into textbox1.

This topic is closed to new replies.

Advertisement