Page 1 of 1

Load and Save not working

Posted: Tue Dec 06, 2022 6:42 pm
by stromecek555
hi, I need help, I'm trying to save or load data but it doesn't work, what's up with that?thank you

Re: Load and Save not working

Posted: Tue Dec 06, 2022 9:27 pm
by Joel
Hi there,

Please could you show me the code you’re using to save and load?

Also you have an error regarding an unassigned reference which is unrelated to Easy Save, but could prevent Easy Save from being able to serialize your data. If this related to something you are saving you should resolve this error.

All the best,
Joel

Re: Load and Save not working

Posted: Wed Dec 07, 2022 1:54 pm
by stromecek555
Hello, thank you for your reply and here are the codes

Code: Select all

public class Load : MonoBehaviour
{
    


    public void LoadSave()
    {
        MaterialsData script = GetComponent<MaterialsData>();
        script.Iron = ES3.Load<int>("Iron");
        script.Scrap = ES3.Load<int>("Scrap");
        script.Wood= ES3.Load<int>("Wood");
        script.Glue = ES3.Load<int>("Glue");
        script.String = ES3.Load<int>("String");
        script.Brass = ES3.Load<int>("Brass");
        script.GunPowder = ES3.Load<int>("GunPowder");
        Debug.Log("Load");
    }
}using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Save : MonoBehaviour
{
   
    
   
    public void Saves()
    {
        MaterialsData script = GetComponent<MaterialsData>();
        ES3.Save(script.Iron,"Iron");
        ES3.Save(script.Scrap,"Scrap");
        ES3.Save(script.Wood,"Wood");
        ES3.Save(script.Glue,"Glue");
        ES3.Save(script.String,"String");
        ES3.Save(script.Brass,"Brass");
        ES3.Save(script.GunPowder,"GunPowder");
        Debug.Log("Save");
    }
}

Re: Load and Save not working

Posted: Wed Dec 07, 2022 1:58 pm
by Joel
Hi there,

You have the parameters the wrong way around in your ES3.Save calls. The key comes first and the value comes second. See the Getting Started guide and docs for more information:

https://docs.moodkie.com/easy-save-3/getting-started/

I also recommend deleting your existing save data by going to Tools > Easy Save 3 > Clear PersistentDataPath, as it will now contain incorrect data.

All the best,
Joel

Re: Load and Save not working

Posted: Wed Dec 07, 2022 3:05 pm
by stromecek555
thank you, but could you show me an example? advise me, they throw me an error, what about it?

Re: Load and Save not working

Posted: Wed Dec 07, 2022 3:14 pm
by Joel
Hi there,

defaultValue should be the value that you want to return if Save data doesn’t exist. As you haven’t declared a variable named defaultValue, this will throw a compilation error (this is a programming error rather than an error at our end).

Also note that your ES3.Save calls still have the parameters the wrong way around.

All the best,
Joel