Archived

This topic is now archived and is closed to further replies.

Save/Load

This topic is 5372 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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).

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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).

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites