Microsoft Azure PlayFab logo
    • Multiplayer
    • LiveOps
    • Data & Analytics
    • Add-ons
    • For Any Role

      • Engineer
      • Designer
      • Executive
      • Marketer
    • For Any Stage

      • Build
      • Improve
      • Grow
    • For Any Size

      • Solo
      • Indie
      • AAA
  • Runs on PlayFab
  • Pricing
    • Blog
    • Forums
    • Contact us
  • Sign up
  • Sign in
  • Ask a question
  • Spaces
    • PlayStream
    • Feature Requests
    • Add-on Marketplace
    • Bugs
    • API and SDK Questions
    • General Discussion
    • LiveOps
    • Topics
    • Questions
    • Articles
    • Ideas
    • Users
    • Badges
  • Home /
  • API and SDK Questions /
avatar image
Question by zidlyx · Aug 02, 2017 at 09:05 AM · apissdksIn-Game EconomyCharacter DataCharacters

UpdateCharacterData problem and characterID .

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
}


Comment

People who like this

0 Show 0
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
Best Answer

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?

Comment

People who like this

0 Show 9 · Share
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image zidlyx · Aug 02, 2017 at 09:11 AM 0
Share

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)

avatar image zidlyx · Aug 02, 2017 at 09:17 AM 0
Share

here is the code for the loggin https://gist.github.com/anonymous/b3b0b94408005892cb5e46ef46d58977

avatar image zidlyx · Aug 02, 2017 at 09:18 AM 0
Share

and its from here public voidUpdateCharacterData(Characterstats characterInfo)

avatar image zidlyx · Aug 02, 2017 at 09:45 AM 0
Share

so is there a way to fix it ?

avatar image Brendan ♦♦ zidlyx · Aug 02, 2017 at 03:14 PM 0
Share

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.

avatar image zidlyx Brendan ♦♦ · Aug 02, 2017 at 06:52 PM 0
Share

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 .

Show more comments
Show more comments
avatar image

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);
    }




}


Comment

People who like this

0 Show 1 · Share
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image zidlyx · Aug 02, 2017 at 09:14 AM 0
Share

this is the loggin scrip its not a answer

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Navigation

Spaces
  • General Discussion
  • API and SDK Questions
  • Feature Requests
  • PlayStream
  • Bugs
  • Add-on Marketplace
  • LiveOps
  • Follow this Question

    Answers Answers and Comments

    2 People are following this question.

    avatar image avatar image

    Related Questions

    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

    PlayFab

    • Multiplayer
    • LiveOps
    • Data & Analytics
    • Runs on PlayFab
    • Pricing

    Solutions

    • For Any Role

      • Engineer
      • Designer
      • Executive
      • Marketer
    • For Any Stage

      • Build
      • Improve
      • Grow
    • For Any Size

      • Solo
      • Indie
      • AAA

    Engineers

    • Documentation
    • Quickstarts
    • API Reference
    • SDKs
    • Usage Limits

    Resources

    • Forums
    • Contact us
    • Blog
    • Service Health
    • Terms of Service
    • Attribution

    Follow us

    • Facebook
    • Twitter
    • LinkedIn
    • YouTube
    • Sitemap
    • Contact Microsoft
    • Privacy & cookies
    • Terms of use
    • Trademarks
    • Safety & eco
    • About our ads
    • © Microsoft 2020
    • Anonymous
    • Sign in
    • Create
    • Ask a question
    • Create an article
    • Post an idea
    • Spaces
    • PlayStream
    • Feature Requests
    • Add-on Marketplace
    • Bugs
    • API and SDK Questions
    • General Discussion
    • LiveOps
    • Explore
    • Topics
    • Questions
    • Articles
    • Ideas
    • Users
    • Badges