Try to load from multiple save list.

Discussion and help for Easy Save 3
Post Reply
lockhighjumpingvenus
Posts: 7
Joined: Wed Oct 11, 2023 9:52 pm

Try to load from multiple save list.

Post by lockhighjumpingvenus »

Hi, I am trying to have the ability to load and save when the player wants. I have set up a save function that allows the player to name their save. and a load function that lists of all save files there are. But I am having an issue with it. I am not sure if i am maybe misunderstanding some of the functions of ES3 or there is something else wrong. Was hoping maybe someone might be able to give a pointer on what may be wrong. Currently, no matter what save I am trying to load, it loads the most recent save.

My save and load function

Code: Select all

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using System;
using UnityEngine.UI;

public class SaveLoadManager : MonoBehaviour
{
    [SerializeField] TMP_InputField inputField;
    [SerializeField] Transform saveButton;
    string inputText;


    private void Awake()
    {
        if (PlayerPrefs.HasKey("SelectedSave"))
        {
            string saveName = PlayerPrefs.GetString("SelectedSave");
            ES3AutoSaveMgr.Current.settings.path = saveName;
            ES3AutoSaveMgr.Current.Load();
        }

        saveButton.GetComponent<Button>().onClick.AddListener(() =>
        {
            updateInputText(inputField.text + ".es3");
        });

    }

    void Update()
    {

    }

    void updateInputText(string inputText)
    {
        this.inputText = inputText;
        Debug.Log(this.inputText);
        saveGame();
    }

    void saveGame()
    {
        ES3AutoSaveMgr.Current.settings.path = this.inputText.ToString();
        ES3AutoSaveMgr.Current.Save();
    }


}
Code to list all files and determine what the buttons do

Code: Select all

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
using System;
using System.Linq;
using UnityEngine.SceneManagement;

public class LoadSystem : MonoBehaviour
{
    
    [SerializeField] Transform loadButtonTemplate;

    float offsetValue = -70;
    float xValue = 120.0f;

    System.DateTime newestDateTime = new System.DateTime(0);

    private void Awake()
    {
        PlayerPrefs.DeleteKey("SelectedSave");
        var saveFiles = ES3.GetFiles().OrderByDescending(f => ES3.GetTimestamp(f)).ToArray();
        loadButtonTemplate.gameObject.SetActive(false);
        int index = 0;
        for (int i = saveFiles.Length - 1; i >= 0; i--)
        {
            var filename = saveFiles[i];
            Transform button = Instantiate(loadButtonTemplate, transform);
            button.gameObject.SetActive(true);
            button.GetComponent<RectTransform>().anchoredPosition = new Vector2(xValue, offsetValue * index);
            index++;
            string fileName = System.IO.Path.GetFileNameWithoutExtension(filename);
            button.Find("fileName").GetComponent<TextMeshProUGUI>().text = fileName;

           

            button.GetComponent<Button>().onClick.AddListener(() =>
            {
                //string selectedFilename = filename;
                string selectedFilename = button.Find("fileName").GetComponent<TextMeshProUGUI>().text.ToString();
                PlayerPrefs.SetString("SelectedSave", selectedFilename);
                GameSceneManager.load(GameSceneManager.Scene.gameScene);
            });

        }
    }

}
Notso
Posts: 51
Joined: Sat May 08, 2021 6:53 pm

Re: Try to load from multiple save list.

Post by Notso »

He has a package with an example of how to use save slots

https://moodkie.com/forum/viewtopic.php?t=2466
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: Try to load from multiple save list.

Post by Joel »

Hi there,

As your issue is likely to be with your logic rather than Easy Save I'm afraid I can only provide limited support. However, I would recommend Debug.Logging the value of ES3AutoSaveMgr.Current.settings.path immediately before saving and loading to check that these are the expected values. For example one might have a file extension but the other might not, meaning you're loading from a different file than you're saving from.
Notso wrote: Mon Feb 19, 2024 12:39 am He has a package with an example of how to use save slots

https://moodkie.com/forum/viewtopic.php?t=2466
Thanks Notso, this may indeed be helpful to them.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
lockhighjumpingvenus
Posts: 7
Joined: Wed Oct 11, 2023 9:52 pm

Re: Try to load from multiple save list.

Post by lockhighjumpingvenus »

Hi thanks for the replies. I had looked at the save slots example but unfortunately wasnt helpful for my issue. I seem to have narrowed down the issue to the game being saved when it shouldnt be (save event has been turned off and should only be saved on a certain button click). Hopefully i should be able to fix this issue though. Just wanted to thank you guys for replying

EDIT : Can I just double check in case I am being an idiot and misunderstanding something. I have save event and load event set to none. I only call

Code: Select all

ES3AutoSaveMgr.Current.Save();
in 1 script (which i currently have commented out for testing - so no saving should take place, right? ) but everytime i stopped the editor from playing, there is a save made. If i have checked the documentation right, this should not be happening, correct?
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: Try to load from multiple save list.

Post by Joel »

Hi there,

If the Save Event and Load Event are set to None in all of your scenes then it shouldn't automatically save. As this isn't happening for us, please could you replicate this in a new project with a simple scene and send it to me using the form at moodkie.com/contact along with step-by-step instructions.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Post Reply