I'm having some trouble getting my Dictionary to load. I have this "recipe unlock" system that checks to see if an entry already exists on file.
It will save the data to a file, but the problem is loading it. I tried following the documentation but am getting errors:
https://docs.moodkie.com/easy-save-3/ge ... bleobjects
https://imgur.com/a/rPdLKu4
https://imgur.com/A3at0aZ
I tried
Code: Select all
recipesDictionary = ES3.Load("recipesDictionary", defaultValue);
Code: Select all
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using ES3Internal;
using ES3Types;
public class RecipeUnlocks : MonoBehaviour
{
// DESC: RECEIVES ALL RECIPE UNLOCKS
// ALSO CHECKS TO SEE IF KEY EXISTS TO BLOCK LEARN ACTION
public static RecipeUnlocks Instance;
void Awake()
{
// INSTANCE CHECK
if (Instance != null)
{
GameObject.Destroy(Instance);
}
else
{
Instance = this;
}
DontDestroyOnLoad(this);
// LOAD DATA ON START INTO LIST
//var defaultValue = 1;
var defaultValue = 1;
ES3.Save("recipesDictionary", recipesDictionary);
recipesDictionary = ES3.Load("recipesDictionary", defaultValue);
}
// DICTIONARY TO STORE UNLOCKED RECIPES
public Dictionary<string, int> recipesDictionary = new Dictionary<string, int>();
// DISPLAY THE LIST IN EDITOR
public List<string> recipesList = new List<string>();
// ADD ITEM TO DICTIONARY/LIST
public void UnlockRecipe(string item)
{
// UNLOCK RECIPE // DISPLAY ON LIST FOR EDITOR
recipesDictionary.Add(item, 1);
recipesList.Add(item);
// SAVE ENTIRE DICTIONARY TO FILE
ES3.Save("recipesDictionary", recipesDictionary);
Debug.Log("Unlocked [" + item + "] Recipe!");
}
// CHECKS TO SEE IF ITEM EXISTS
public bool CheckRecipe(string item)
{
// check entire dictionary for recipe
foreach (KeyValuePair<string, int> kvp in recipesDictionary)
{
if (kvp.Key == item)
{
Debug.Log("FOUND ITEM, TRUE");
return true;
}
}
// else return false
Debug.Log("ITEM NOT FOUND, FALSE");
return false;
}
}