- Title: Custom Saving and Loading
- Description: The purpose of these scripts is to have a proper way to save and load your game. Sure, the default GM savesystem is decent enough, but it's pretty rare to need to save EVERYTHING there is, so I wrote this thing.
- GM Version: I used GM7
- Registered: No, at least I don't think so
- File Type: zip
- File Size: 18,6kB
- File Link: http://www.box.net/shared/2me1ylcf83
I couldn't find any other topics on how to do this so I had to figure it out on my own. At first I did it way too complicated with a switch-statment in a loop checking for every single variable I'd use, but at some point I stumbled over variable_global_set and it blew my mind how simple it was to do the saving and loading with only 20 lines of code and a seperate text-file.
If you credit me for this, then that's cool. If you don't , then I'm fine with that too. I have better things to do than chase after people who had the nerve to use something I put up on the Internet.
Here's the loading script, without commenting for the sake of being neat: (There's commenting in the downloadable file)
var file, value, item;
if file_exists(argument0)
{
file = file_text_open_read(argument0);
while (!file_text_eof(file))
{
item = file_text_read_string(file);
value = real(string_digits(item));
if (item != "")
{variable_global_set(string_letters(item), value);}
file_text_readln(file);
}
file_text_close(file);
return(true);
}
else
{return(false);}
And here's the saving script:
Not that you'll NEED the default-file.
var file, item, value;
if (file_exists("default.sav"))
{
varfile = file_text_open_read("default.sav");
file = file_text_open_write(argument0);
while (!file_text_eof(varfile))
{
item = string_letters((file_text_read_string(varfile)));
value = variable_global_get(item);
if (item != "" && variable_global_exists(item))
{file_text_write_string(file, string(item) + " = " +string(round(value)));}
file_text_writeln(file);
file_text_readln(varfile);
}
file_text_close(varfile);
file_text_close(file);
return(true);
}
else
{ return(false);}











