Hi folks. I am trying to get Player Data from my saved data. SetUserData working perfectly fine. I can see Player Data in my Game Manager. However when I paste GetUserData codes, PlayFabId = PlayFabId, give me an error on code. As in the KongregateHandler script, I change it to KongregateId = kongregateId, still give me an error on code. So how I get my saved player data?
These are KongregateHandler and GetUserData scripts.
public void GetUserData() { PlayFabClientAPI.GetUserData(new GetUserDataRequest() { PlayFabId = PlayFabId, Keys = null }, result => { Debug.Log("Got user data:"); if (result.Data == null || !result.Data.ContainsKey("damage")) Debug.Log("No damage"); else Debug.Log("damage: " + result.Data["damage"].Value); }, (error) => { Debug.Log("Got error retrieving user data:"); Debug.Log(error.GenerateErrorReport()); }); }
// We are specifically interested in importing PlayFab related namespaces using PlayFab; using PlayFab.ClientModels; using UnityEngine; using UnityEngine.UI; public class KongregateHandler : MonoBehaviour { // Standard unity callback, executed once for the script to start public void Start() { // Utility: show feedback SetMessage("Loading kongregate api..."); /* * Important: execute Javascript in the external context to initialize * Kongregate API, Unity Support and set up callback GameObject and Method. * In this case, callback is set to a GameObject called Kongregate and a * method called OnKongregateAPILoaded, which we define later in this class. * Once Kongregate API is initialized, Unity will locate this object by name * ("Kongregate") and execute a method "OnKongregateAPILoaded" passing in user * info string as an argument. */ Application.ExternalEval( "if(typeof(kongregateUnitySupport) != 'undefined'){" + " kongregateUnitySupport.initAPI('Kongregate', 'OnKongregateAPILoaded');" + "} else {" + " console.error('No unity support!');" + "};" ); } /* * Executed once Kongregate API is ready. This method is invoked by KongregateAPI * and receives a structured text with multiple pieces of data you must parse manually. * The userInfo string parameter has the following structure: 'user_identifier|user_name|auth_token' */ public void OnKongregateAPILoaded(string userInfo) { SetMessage("Recieved user info! Logging though playfab..."); // We split userInfo string using '|' character to acquire auth token and Kongregate ID. var userInfoArray = userInfo.Split('|'); var authTicket = userInfoArray[2]; var kongregateId = userInfoArray[0]; LogToBrowser("Auth Token: " + authTicket); LogToBrowser("Kongregate Id: " + kongregateId); /* * We then execute PlayFab API call called LoginWithKongregate. * LoginWithKongregate requires KongregateID and AuthTicket. * We also pass CreateAccount flag, to automatically create player account. */ PlayFabClientAPI.LoginWithKongregate(new LoginWithKongregateRequest { KongregateId = kongregateId, AuthTicket = authTicket, CreateAccount = true }, OnLoggedIn, OnFailed); } /* * The rest of the code serves as a utility to process results, log debug statements * and display them using Text message label. */ private void OnLoggedIn(LoginResult obj) { SetMessage("Logged in through PlayFab!"); } private void OnFailed(PlayFabError error) { SetMessage("Failed to login in with PlayFab: " + error.GenerateErrorReport()); } private void SetMessage(string message) { InfoLabel.text = message; } private void LogToBrowser(string message) { Application.ExternalEval(string.Format("console.log('{0}')", message)); } public Text InfoLabel; }