Can I save the game once at "Game End" event instead of saving every time the player picks an item?

M

meme

Guest
Hello everyone, I almost finish my platformer game but I have a doubt on how to do optimize the saving mechanism.
So basically I have a global struct, containing everything, such as lists of player armors, guns, etc, as well as player's coins.

My thought on saving is to get back on our progress which means loading the game is only required once, for me it's inside the "Game Start" event. But does this necessarily means progress just needs to be saved once which is on the "Game End" event of a persistent Game Manager object?

For my game, what needs to be saved is when crafting an item, buy items from a store, equipping items, collect coins from levels, etc.
Most of them are acceptable except for collecting coins since there might be 20 coins collected at once. I know that I can separate the save files but I like it to be organized 😗.

Here's my save script:
GML:
// Save progress
function save_progress()
{
    var _struct = {
        playerList: global.playerList,
        scarfList: global.scarfList,
        auraList: global.auraList,
        powerList: global.powerList,
        levelList: global.levelList,
        playerInfo: global.playerInfo
    }
    
    // Stuffs
    var _string = json_stringify(_struct);
    var _buffer = buffer_create(string_byte_length(_string)+1, buffer_fixed, 1);
    buffer_write(_buffer, buffer_string, _string);
    buffer_save(_buffer, SAVEFILE);
    buffer_delete(_buffer);
}
Thanks for reading, so what do you think of my theory on loading+saving the game once?
 

FrostyCat

Redemption Seeker
It's up to you decide when to save, but you must be aware that while the Game Start event is guaranteed to fire, the Game End event is not. It won't trigger if your game crashes, gets force-killed by the OS, or if the system shuts down unexpectedly. If you are fine with losing fine-scale process under these conditions, go ahead.
 

Yal

🐧 *penguin noises*
GMC Elder
In binary files, you can write individual bytes (file_bin_seek / file_bin_write_byte) so if saving all the data takes a lot of time and you want to save many small changes, this could be a way to go.

(Make sure to open them with file_bin_open instead of file_bin_rewrite; rewrite will clear the file first, erasing all the existing data!)
 
It's really up to you if you want an "autosave" every once in a while, or you want to let the player decide when to save his game.
To me, this is really more for the User Experience departement than the programming side, as this will influence the gameplay a lot and break the frustration-reward balance if the savepoints are too few and in-between. Forgetting to save and dying is ALSO frustrating, so , for me, I like the games that have a little bit of the two. Say an autosave when I pass important/tough or boring parts, and then have the liberty to save whenever (if possible) within that.
Having a misclick commited to a save is really frustrating for me (like XCOM Ironman mode, for example), this breaks the experience a little.
 
  • Like
Reactions: Tyg
Basically what Frosty said

Having saved dependent on the game closing or the player doing it manually is a bad idea because if the game crashes it might not register the game end events where it happens. You want there to be set save points like entering different rooms or crossing checkpoint flags where an autosave happens as an anti-frustration feature
 
M

meme

Guest
It's up to you decide when to save, but you must be aware that while the Game Start event is guaranteed to fire, the Game End event is not. It won't trigger if your game crashes, gets force-killed by the OS, or if the system shuts down unexpectedly. If you are fine with losing fine-scale process under these conditions, go ahead.
Ahh this makes sense, thanks!
 
Top