Hi all,
I have a game that, after ending, gets back to the main menu. Since I'm lazy, I just called SetRestartPoint when entering the menu room the first time, and RestartGame when the ending cutscene is over. It works like a charm, every variable is back to the initial state.
The problem is that this resets also every in-game setting to the default one. Since it's just really four things (music and sound volume, text speed, text skip), is there a way of avoiding that these are reset when calling RestartGame?
Quote from: guga2112 on Wed 02/12/2020 18:33:35
The problem is that this resets also every in-game setting to the default one. Since it's just really four things (music and sound volume, text speed, text skip), is there a way of avoiding that these are reset when calling RestartGame?
Write them into a custom file and read after restore game. This will solve loosing these options when player loads a regular save too.
See File functions in the manual, it's pretty simple to use if you only need to save/load few ints.
Reading these values could be done in on_event function, event being eEventRestoreGame.
Example, in which you call your custom LoadGame function to load game instead of RestoreGameSlot directly.
void LoadGame(int slot)
{
// Save custom config
File* f = File.Open("$SAVEGAMEDIR$/config.dat", eFileWrite);
f.WriteInt(music_vol);
f.WriteInt(sound_vol);
// etc...
f.Close();
RestoreGameSlot(slot); // load game now
}
void AfterLoadGame()
{
File* f = File.Open("$SAVEGAMEDIR$/config.dat", eFileRead);
music_vol = f.ReadInt();
sound_vol = f.ReadInt();
// etc...
f.Close();
// Apply sliders, volume and so on
}
function on_event (EventType event, int data)
{
if (event == eEventRestoreGame)
{
AfterLoadGame();
}
}