MFGG Forums
GM Studio 2's save system is bugging me - Printable Version

+- MFGG Forums (https://forums.mfgg.net)
+-- Forum: MFGG (https://forums.mfgg.net/forumdisplay.php?fid=4)
+--- Forum: Developer Discussion (https://forums.mfgg.net/forumdisplay.php?fid=10)
+--- Thread: GM Studio 2's save system is bugging me (/showthread.php?tid=365)



GM Studio 2's save system is bugging me - VinnyVideo - 01-13-2018

I used similar code to save files in GM 8, but when I use it in GM Studio 2, it won't save a file in the location that the ApplicationData environment variable points to. It seems that the AppData environment variable works a little differently in newer versions of GM, so what I am doing wrong here?

Code:
if file_exists(environment_get_variable("ApplicationData")+"\gamename.sav")
    file_delete(environment_get_variable("ApplicationData")+"\gamename.sav");
    
var file = file_text_open_write(environment_get_variable("ApplicationData")+"\gamename.sav");

var savelist = ds_list_create();
ds_list_add(savelist, global.boringVariableName);

var savestr = ds_list_write(savelist);
file_text_write_string(file, savestr);
ds_list_destroy(savelist);

file_text_close(file);



RE: GM Studio 2's save system is bugging me - Miles - 01-13-2018

You can probably shave off all the environment variable stuff and just use direct filenames as the strings.

Starting in Game Maker Studio they sandboxed the environment, meaning you can only save to a certain predetermined spot unless you get around it with an extension or directly ask the user for a directory with certain functions. It shoves game saves in %localappdata%\<Game Name>. If you want a specific single directory rather than the forced one, you'll want to track down an extension to do so - this one may or may not help? (Seemed to be the only free one of this kind that claimed GMS2 compatibility, but I can't test this myself.)

https://docs2.yoyogames.com/source/_build/1_overview/3_additional_information/file_system.html - This explains it infinitely better than I can.


RE: GM Studio 2's save system is bugging me - Syaxamaphone - 01-13-2018

Yeah Miles pretty much answered your question. GMS file functions by default can read the application's folder and read/write its appdata folder. It will actually always attempt to read the game's folder first. If it doesn't find the file, it moves to check appdata next.

So if you want to save just indicate the filename without a directory and it will automatically save/load from the game's appdata folder (which it will automatically make for you when it runs).

To access appdata, you can use Windows+R to open the run command and then type in 'appdata'. You'll then find your game's folder in appdata/local/<name of game>.


RE: GM Studio 2's save system is bugging me - VinnyVideo - 01-17-2018

@Miles @Syaxamaphone Thanks for the insight. Upon further review, the game did save my file - just not in the location I was expecting!