question

Kenneth Hopson avatar image
Kenneth Hopson asked

generateErrorReport as UI Text

Hey, so i'm trying to get this result shown here, but as any error message it throws out.

i don't know what else to say/explain so here's my horrid code

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using PlayFab;
using PlayFab.ClientModels;
using PlayFab.DataModels;
using PlayFab.ProfilesModels;
using UnityEngine.UI;
using TMPro;


public class Register : MonoBehaviour {


    public TMP_InputField Username;
    public TMP_InputField Password;
    public TMP_InputField ConfirmPass;
    public TMP_InputField Email;
    public GameObject Error;
    public TMP_Text ErrText;


    public void CreateAccount()
    {
        if(Password.text == ConfirmPass.text)
        {
            RegisterPlayFabUserRequest request = new RegisterPlayFabUserRequest();
            request.Username = Username.text;
            request.Password = ConfirmPass.text;
            request.Email = Email.text;
            request.DisplayName = Username.text;


            PlayFabClientAPI.RegisterPlayFabUser(request, result => {
                Debug.Log("Account Created with username: " + result.Username + " !");


            }, error => {
                Error.GetComponent<Animator>().Play("Fade-in");


                ErrText.text = "Email is not valid example"; // this is supposed to be where playfab returns errors, like "username must be 3 and 20 characters"
                Debug.Log("some error happened, oops!");
                Debug.LogError(error.GenerateErrorReport()); // this generateErrorReport, whatever comes out of this is what I need to show in the text of that window, thanks!


            });
        }
    }
}


Any help would be appreciated! Thanks

unity3ddata
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Kenneth Hopson avatar image Kenneth Hopson commented ·

Update: i got the thing around line 42-44 working
still need help with the text showing in the actual window

    public void CreateAccount()
    {
        if(Password.text == ConfirmPass.text)
        {
            RegisterPlayFabUserRequest request = new RegisterPlayFabUserRequest();
            request.Username = Username.text;
            request.Password = ConfirmPass.text;
            request.Email = Email.text;
            request.DisplayName = Username.text;


            PlayFabClientAPI.RegisterPlayFabUser(request, result => {
                Debug.Log("Account Created with username: " + result.Username + " !");


            }, error => {
                Error.GetComponent<Animator>().Play("Fade-in");
                ErrText.text = PlayFabClientAPI.GenerateErrorReport; // i've gotten this to work, but it doesn't show the error, like "between 3 and 20 chars" inside the window
                Debug.Log("some error happened, oops!");
                Debug.LogError(error.GenerateErrorReport()); 


            });
        }
    }
}


0 Likes 0 ·

1 Answer

·
Hernando avatar image
Hernando answered

I guess the ErrorDetails property might be suitable for your scenario.

Take the screenshot attached as an example, here call Client.LoginWithEmailAddress API and without fill in the Email and Password field. It will then return one or more error value in the ErrorDetasils property.

For the code that displays in the actual window, you can refer below:

ErrText.text = ""
error.ErrorDetails["Email"].ForEach(detail => {
ErrText.text + detail
});

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.