Loading to JSON

Discussion and help for Easy Save 3
Post Reply
Friction
Posts: 6
Joined: Sat Nov 25, 2017 3:14 pm

Loading to JSON

Post by Friction »

Hello,

I was saving my files as JSON.
I started using Easy Save because I want to encrypt my saves.
There is no problem with saving. Here is my script:

Code: Select all

		private void Save()
		{
			Dictionary<string, object> saveJson = new Dictionary<string, object>();

			for (int i = 0; i < saveables.Count; i++)
			{
				saveJson.Add(saveables[i].SaveId, saveables[i].Save());
			}

			//System.IO.File.WriteAllText(SaveFilePath, Utilities.ConvertToJsonString(saveJson));

			ES3.Save("EncrytedSaves", saveJson);
		}
But I can't load them back. I was using this code to load variables:

Code: Select all

		private bool LoadSave(out JSONNode json)
		{
			json = null;

			if (!System.IO.File.Exists(SaveFilePath))
			{
				return false;
			}
			json = JSON.Parse(System.IO.File.ReadAllText(SaveFilePath));

			return json != null;
		}
Can I convert file content to JSON? Do you have a suggestion?
Regards,
User avatar
Joel
Moodkie Staff
Posts: 4846
Joined: Wed Nov 07, 2012 10:32 pm

Re: Loading to JSON

Post by Joel »

Hi there,

I don't appear to see where you are calling ES3.Load to load the data you saved?

For information on how to use Easy Save please see the Getting Started guide:
https://docs.moodkie.com/easy-save-3/getting-started/

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Friction
Posts: 6
Joined: Sat Nov 25, 2017 3:14 pm

Re: Loading to JSON

Post by Friction »

Hello again,

Thank you for your quick reply.
Here is my function to load saved data:

Code: Select all

		private bool LoadSave(out JSONNode json)
		{
			json = null;
			if (!ES3.FileExists())
			{
				return false;
			}
			json = ES3.LoadRawString();
			return json != null;
		}
		
I am getting "NullReferenceException: Object reference not set to an instance of an object" error.
Friction
Posts: 6
Joined: Sat Nov 25, 2017 3:14 pm

Re: Loading to JSON

Post by Friction »

Hello,

I am so sorry to disturb you. I've find the solution.
So here is my script:

Code: Select all

		/// <summary>
		/// Saves all registered saveables to the save file
		/// </summary>
		private void Save()
		{
			Dictionary<string, object> saveJson = new Dictionary<string, object>();

			for (int i = 0; i < saveables.Count; i++)
			{
				saveJson.Add(saveables[i].SaveId, saveables[i].Save());
			}

			string newString = Utilities.ConvertToJsonString(saveJson);
			ES3.SaveRaw(newString);
		}

		/// <summary>
		/// Tries to load the save file
		/// </summary>
		private bool LoadSave(out JSONNode json)
		{
			json = null;
			if (!ES3.FileExists())
			{
				return false;
			}
			string newString = ES3.LoadRawString(ES3Settings.defaultSettings);
			json = JSON.Parse(newString);
			return json != null;
		}
		
Thanks for everything.
Best regards,
Post Reply