I feel dumb because this must not be TOO complicated with so many people using these features and so few questions/materials online about it, but I simply cannot get these to work.
I can successfully log in to Playfab with an associated PlayFabID (linked with Kongregate). No problems there. However, when I try to save/load data, I am running into problems. I get an "invalid input parameters" every time I try to save a JSON string. So my player data never actually gets updated, and therefore never loaded either.
My save data code looks like this:
// convert this GameManager (all public user data fields) to JSON public string convertToJson() { return JsonUtility.ToJson(this); }
var updateRequest = new PlayFab.ServerModels.UpdateUserInternalDataRequest(){ PlayFabId = playFabID, Data = newDictionary<string,string>() { {"UserData", GameManager.Instance.convertToJson()}, }, }; PlayFabServerAPI.UpdateUserInternalData(updateRequest,(result)=> { Debug.Log("Set internal user data successful"); },(error)=>{ Debug.Log("Got error updating internal userdata:"); Debug.Log(error.ErrorMessage); });
My load data code looks like this:
// update GameManager class (all public user data fields) from JSON to values public void convertFromJson(string jsonString) { JsonUtility.FromJsonOverwrite(jsonString, this); }
var getUserDataRequest=new PlayFab.ServerModels.GetUserDataRequest(){ PlayFabId = playFabID, }; PlayFabServerAPI.GetUserInternalData(getUserDataRequest,(result)=>{ Debug.Log("Got the following user internal data:"); foreach(var entry in result.Data) { Debug.Log(entry.Key+":"+entry.Value.Value); GameManager.Instance.convertFromJson(entry.Value.Value); } },(error)=>{ Debug.Log("Got error getting internal user data:"); Debug.Log(error.ErrorMessage); });
I saw something online about a .stringify() function, but I can't seem to use that in my code? But maybe since I am using convertToJson rather than that, that is why I am getting invalid parameters error?
Any help would be greatly appreciated... I have been stuck on this for days and getting insanely frustrated :(
Thanks,
Tom