Legacy GM Help with the ds_map_secure functions

A

Ariak

Guest
Hey,

I'm working on menus atm and was trying use the ds_map_secure_save and ds_map_secure_load functions to easily store settings info. However, when I reopen my game it can't find the save_file. The documentation only reads stored in a " safe location on the target platform". Maybe i need to create the savefile first?...

Here's the code.
Code:
var settings_file="settings.dat";
if file_exists(settings_file) {file_delete(settings_file)}  //delete old.
var settings_map=ds_map_create();
settings_map[? "c_resolution"]=c_resolution;
settings_map[? "c_language"]=global.c_language;
ds_map_secure_save(settings_map, settings_file);
ds_map_destroy(settings_map);

Code:
var settings_file="settings.dat";
var save=file_exists(settings_file)
var settings_map=-1;
if save {
    settings_map=ds_map_secure_load(settings_file);
}
    // STUFFS
if ds_exists(settings_map,ds_type_map){ ds_map_destroy(settings_map);}

Any help would be greatly appreciated :)
 

jo-thijs

Member
I don't have any experience with this,
but it sounds like ds_map_secure_save might be operating in a different directory (or yet even something entirely different) than file_exists.
This might lead to save being false, even though the saved map is there.

EDIT:
Actually, I just tested that theory and it isn't true.

What is the value of save and of settings_map?

EDIT:
I actually just tested your exact codes and they worked just fine for me.
Are your files actually being saved?
Are they being prevented from being saved somehow?
Is something deleting them afterwards?
 
Last edited:
A

Ariak

Guest
save is 0 - thus false!
I just ran my game and thus created a savefile (upon game end).
Afterwards I then manually set save to true to force it to execute ds_map_secure_load upon loading. It returns the predicted result: a crash - trying to access non existent data structure.

As an afterthought: I cannot find the save file in the %appdata% folder at all. Its possible its stored somewhere else.
 
Last edited by a moderator:
A

Ariak

Guest
EDIT: I got it working!
My error was a bit stupid - the save function was never called, as it was inside an instance_destroy event. Apparently using the game_end() function skips the destroy events completely.

It saves to the %appdata% folder.

Code:
settings_file=working_directory+"settings.dat";
var save=file_exists(settings_file); // i need this for later checks if i should update variables from the file.
if save { var settings_map=ds_map_secure_load(settings_file);} else { var settings_map=-1;} //creates a map or sets dummy value

Code:
if file_exists(settings_file) {file_delete(settings_file)}
var settings_map=ds_map_create();
settings_map[? "c_resolution"]=c_resolution;
settings_map[? "c_language"]=global.c_language;
ds_map_secure_save(settings_map, settings_file);
ds_map_destroy(settings_map);
 
Last edited by a moderator:
Top