Save game in specific scenes or script's line

Discuss authoring naninovel scenario scripts.
Post Reply
kentaruu97
Posts: 3
Joined: 17 Mar 2022 01:34

Save game in specific scenes or script's line

Post by kentaruu97 »

I wonder if I could save the game in some specific scenes or specific script's line in-game?

For example:
In the scene, players save between 2 big scenes, and I want when they load that save file, the game will start in the previous script's line or some specific line that made different choices.

Anyone can help me with this?

I really need it, please!

idaot
support
Posts: 263
Joined: 01 Aug 2020 08:25

Re: Save game in specific scenes or script's line

Post by idaot »

You can use @save (https://naninovel.com/api/#save) to save to a quick save slot. For more complex behaviour I suggest overriding IStateManager to make the save & load system more checkpoint-based. Alternatively consider disabling the option to save during key moments by creating a custom command.

kentaruu97
Posts: 3
Joined: 17 Mar 2022 01:34

Re: Save game in specific scenes or script's line

Post by kentaruu97 »

idaot wrote: 17 Mar 2022 08:08

You can use @save (https://naninovel.com/api/#save) to save to a quick save slot. For more complex behaviour I suggest overriding IStateManager to make the save & load system more checkpoint-based. Alternatively consider disabling the option to save during key moments by creating a custom command.

Thanks for the reply!
I thought about this but I'm not so sure about that. Since you mention it, I'll give it a try, thank you!

kentaruu97
Posts: 3
Joined: 17 Mar 2022 01:34

Re: Save game in specific scenes or script's line

Post by kentaruu97 »

idaot wrote: 17 Mar 2022 08:08

You can use @save (https://naninovel.com/api/#save) to save to a quick save slot. For more complex behaviour I suggest overriding IStateManager to make the save & load system more checkpoint-based. Alternatively consider disabling the option to save during key moments by creating a custom command.

I tried to change the Save of StateManager script like this one

Code: Select all

public virtual async UniTask<GameStateMap> SaveGameAsync(string slotId, bool isQuickSave)
        {
            var quick = slotId.StartsWithFast(Configuration.QuickSaveSlotMask.GetBefore("{"));

        OnGameSaveStarted?.Invoke(new GameSaveLoadArgs(slotId, quick));

        var state = new GameStateMap();
        await scriptPlayer.SynchronizeAndDoAsync(DoSaveAfterSync);

        OnGameSaveFinished?.Invoke(new GameSaveLoadArgs(slotId, quick));

        return state;

        async UniTask DoSaveAfterSync()
        {
            if (isQuickSave)
            {
                state.SaveDateTime = DateTime.Now;
                state.Thumbnail = cameraManager.CaptureThumbnail();

                SaveAllServicesToState<IStatefulService<GameStateMap>, GameStateMap>(state);
                PerformOnGameSerializeTasks(state);
                state.RollbackStackJson = SerializeRollbackStack();
                state.CurrentScene = SceneManager.GetActiveScene().buildIndex.ToString();
                state.SWPos = SnowWhitePosition();
                await GameSlotManager.SaveAsync(slotId, state);
                // Also save global state on every game save.
                await quickSaveGlobalAsync();
                lastCheckPoint = state;
            }
            else
            {
                if (lastCheckPoint != null)
                {
                    state.SaveDateTime = lastCheckPoint.SaveDateTime;
                    state.Thumbnail = lastCheckPoint.Thumbnail;

                    SaveAllServicesToState<IStatefulService<GameStateMap>, GameStateMap>(lastCheckPoint);
                    PerformOnGameSerializeTasks(lastCheckPoint);
                    state.RollbackStackJson = lastCheckPoint.RollbackStackJson;
                    state.CurrentScene = lastCheckPoint.CurrentScene;
                    state.SWPos = lastCheckPoint.SWPos;

                    await GameSlotManager.SaveAsync(slotId, state);

                    // Also save global state on every game save.
                    await SaveGlobalAsync();
                }
                else
                {
                    await GameSlotManager.SaveAsync(slotId, null);
                    // Also save global state on every game save.
                    await SaveGlobalAsync();
                }
            }

        }
    }

But when I tried to load it, It went wrong and... not crash nor show any bugs, it's just... very wrong and not like the quicksave file.
I did something wrong in there? I can't find any clue to fix this ;;-;;

idaot
support
Posts: 263
Joined: 01 Aug 2020 08:25

Re: Save game in specific scenes or script's line

Post by idaot »

I don't recommend changing the Naninovel code but instead override IStateManager (https://naninovel.com/guide/engine-serv ... n-services) That way you can actively compare and debug the two services.

I also recommend reading on State Management if you haven't already: https://naninovel.com/guide/state-manag ... game-state

Post Reply