GameMakerHelpBlog

Sunday, November 26, 2006

Save and Load - Save your game properly

This code is for saving your game through directories and is good for saving your game....
-Copying files to change the extention
E.g i have a file which is text and i want to change it .dll i would go.
file_copy(example.txt,example.dll)
filename_change_ext(example.txt,example.dll)
or you can use global vars but it will require to do some editing to the code so i don't recommend it.

Anyway here is the code for saving your game
Remember [code]&[/code] has nothing to do with the code it is just there to tell you tha it is code

[code]

SaveGameName = "";
SaveGameName = get_save_filename("Save Files (*.sav)*.sav", "");
if (SaveGameName != "")
{
if (string_copy(SaveGameName, string_length(SaveGameName) - 3, 4) != ".sav")
{
SaveGameName = SaveGameName + ".sav";
}
game_save(SaveGameName);
}
[/code]
And for loading
[code]

LoadGameName = "";
LoadGameName = get_open_filename("Saved Games (*.sav)*.sav", "");
if (LoadGameName != "")
{
if (string_copy(LoadGameName, string_length(LoadGameName) - 3, 4) != ".sav")
{
LoadGameName = LoadGameName + ".sav";
}
game_load(LoadGameName);
}
[/code]

Labels:

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home