Hello so we are working with the sdk playfab on out project so wer made a login screen then we have a charactere cration screen but for not we are just gonna gonna have 2 buttons "back" and "creat"
so we were trying to make a character id so we update the charcter data but it seems like we need the character data but its not even created yet can we have a example script or something to build on a character id etc .
this is our code
using System.Collections; using System.Collections.Generic; using UnityEngine; using PlayFab; using PlayFab.ClientModels; using UnityEngine.UI; public class playfabCharacter : MonoBehaviour { private string PlayFabId; private string CharacterID; public void UpdateCharacterData(Characterstats characterInfo) { Dictionary<string, string> charData = new Dictionary<string, string>() { {"Class", "Mage"}, //characterInfo.cClass.ToString() {"Race","human"}, // characterInfo.Race { "Power", "99999" } //characterInfo.Power.ToString() }; UpdateCharacterDataRequest request = new UpdateCharacterDataRequest(); // request.CharacterId = "1" ; request.Data = charData; PlayFabClientAPI.UpdateCharacterData(request, (result) => { Debug.Log("Successfully updated user data"); }, (error) => { Debug.Log("Got error setting user data Ancestor to Arthur"); Debug.Log(error.ErrorMessage); }); } public void CharacterCreation() { Characterstats newCharacter = new Characterstats(); newCharacter.Race = "Human";//though I recommend making this an enum newCharacter.cClass = CharacterClass.Warrior; newCharacter.Power = 1; UpdateCharacterData(newCharacter); } } public class Characterstats { public string name = ""; public int level = 1; public CharacterClass cClass = CharacterClass.Warrior; public string Race = ""; public int Power = 1; } public enum CharacterClass { Warrior, Mage, Priest }
Answer by Brendan · Aug 02, 2017 at 09:05 AM
Can you let us know the specific error message you're getting back, and from which call? How are you granting the character to the player account to start?
Invalid input parameters UnityEngine.Debug:Log(Object) playfabCharacter:<UpdateCharacterData>m__1(PlayFabError) (at Assets/playfabCharacter.cs:36) PlayFab.Internal.<MakeApiCall>c__AnonStorey1:<>m__0(String) (at Assets/PlayFabSdk/Shared/Internal/PlayFabHttp/PlayFabWWW.cs:115) PlayFab.Internal.<Post>c__Iterator0:MoveNext() (at Assets/PlayFabSdk/Shared/Internal/PlayFabHttp/PlayFabWWW.cs:176) UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)
here is the code for the loggin https://gist.github.com/anonymous/b3b0b94408005892cb5e46ef46d58977
and its from here public voidUpdateCharacterData(Characterstats characterInfo)
So again, how are you granting the character to the player? A character only exists on a player if one has been granted. Also, the CharacterId is required on that call, to state which character belonging to the player you're updating.
well thats what im trying to do can you help me make a character so it can be granted to the player i dont have a character to grat
right now i have a player logged in thats all .
Answer by zidlyx · Aug 03, 2017 at 02:35 AM
for the login code here it is
using PlayFab; using PlayFab.ClientModels; using UnityEngine; using System.Collections; using System.Collections.Generic; using UnityEngine.UI; public class PlayFabLogin : MonoBehaviour { private static string playerID; public static string PlayerID { get { return playerID; } } public GameObject errorRegister; public GameObject errorLogin; public GameObject SuccessRegister; public GameObject SuccessLogin; public GameObject creatPanel; public GameObject loginPanel; public void Start() { PlayFabSettings.TitleId = "BE31"; // Please change this value to your own titleId from PlayFab Game Manager creatPanel.SetActive(false); loginPanel.SetActive(true); errorRegister.SetActive(false); errorLogin.SetActive(false); SuccessRegister.SetActive(false); SuccessLogin.SetActive(false); } public void LoginPlayFabAccount(string _username, string _password) { if (_username.Contains("@")) { LoginWithEmailAddressRequest loginRequest = new LoginWithEmailAddressRequest(); loginRequest.Email = _username; loginRequest.Password = _password; PlayFabClientAPI.LoginWithEmailAddress(loginRequest, OnLoginPlayFabAccountSuccess, OnLoginPlayFabAccountFailure); } else { LoginWithPlayFabRequest loginRequest = new LoginWithPlayFabRequest(); loginRequest.Username = _username; loginRequest.Password = _password; PlayFabClientAPI.LoginWithPlayFab(loginRequest, OnLoginPlayFabAccountSuccess, OnLoginPlayFabAccountFailure); } } private void OnLoginPlayFabAccountSuccess(LoginResult _result) { SuccessLogin.SetActive(true); playerID = _result.PlayFabId; StartCoroutine(CharacterSelection()); Debug.LogFormat("Logged in user with PlayFab ID {0}.", _result.PlayFabId); } private void OnLoginPlayFabAccountFailure(PlayFabError _error) { errorLogin.SetActive(true); playerID = null; Debug.LogWarning("Failed to login user:"); Debug.LogError(_error.GenerateErrorReport()); } public void Register(string _username, string _password, string _email) { { RegisterPlayFabUserRequest registerRequest = new RegisterPlayFabUserRequest(); registerRequest.Username = _username; registerRequest.Password = _password; registerRequest.Email = _email; PlayFabClientAPI.RegisterPlayFabUser(registerRequest, OnRegisterSuccess, OnRegisterFailure); } } public void OnRegisterSuccess(RegisterPlayFabUserResult _result) { StartCoroutine(Back()); Debug.LogFormat("Registered {0} with PlayFab ID {1}.", _result.Username, _result.PlayFabId); StartCoroutine(SuccessReg()); } public void OnRegisterFailure(PlayFabError _error) { errorRegister.SetActive(true); Debug.LogWarning("Failed to register user:"); Debug.LogError(_error.GenerateErrorReport()); } public void AccountRecover(string _email) { if (_email.Contains("@")) { SendAccountRecoveryEmailRequest recoverPass = new SendAccountRecoveryEmailRequest(); recoverPass.Email = _email; recoverPass.TitleId = "BE31"; PlayFabClientAPI.SendAccountRecoveryEmail(recoverPass, OnRecoverSuccess, OnRecoverFailure); } } public void OnRecoverSuccess(SendAccountRecoveryEmailResult _result) { Debug.Log("Check your mail"); } public void OnRecoverFailure(PlayFabError _error) { Debug.LogWarning("Failed to register user:"); Debug.LogError(_error.GenerateErrorReport()); } // private void OnLoginSuccess(LoginResult result) // { // Debug.Log("Congratulations, you made your first successful API call!"); // } private void OnLoginFailure(PlayFabError error) { errorLogin.SetActive(true); Debug.LogWarning("Something went wrong with your first API call. :("); Debug.LogError("Here's some debug information:"); Debug.LogError(error.GenerateErrorReport()); } IEnumerator CharacterSelection() { yield return new WaitForSeconds(2f); Application.LoadLevel("Level1"); } IEnumerator Back() { yield return new WaitForSeconds(2f); creatPanel.SetActive(false); loginPanel.SetActive(true); } IEnumerator SuccessReg() { SuccessRegister.SetActive(true); yield return new WaitForSeconds(3f); SuccessRegister.SetActive(false); } }
Grant items to a character without server api? 1 Answer
How to call SetObjects to create an object with the correct entity type 1 Answer
Apple (iOS) receipt validation in Unity IAP 1 Answer
UpdateCharacterReadOnlyData Vs UpdateCharacterData 0 Answers
ModifyItemUSes On Character Inventory... 3 Answers