question

MoonHeonYoung avatar image
MoonHeonYoung asked

display name check

Hello

I want to know if the displayName is being used before calling "UpdateUserTitleDisplayName".

scenario

The player already has a displayName During the game,

the player wants to change the displayName by consuming currency.

that is,

I want to create a duplicate check function.

If AccountNotFound is returned by calling GetAccountInfo, should it be determined that the displayName does not exist?

Or is there a better way?

If I have to call GetAccountInfo please tell me how to catch the error

10 |1200

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

1 Answer

·
Rick Chen avatar image
Rick Chen answered

Generally, when you call UpdateUserTitleDisplayName API with an existing name, it will return the error “NameNotAvailable”. You could tell whether the name is already used with this error.

Since you want to check whether the display name is used before calling UpdateUserTitleDisplayName API, yes you could use the GetAccountInfo to check whether an account with the name exists or not.

However, checking whether a display name is duplicated using the GetAccountInfo API before calling UpdateUserTitleDisplayName does not mean that it will be successful when calling UpdateUserTitleDisplayName. Because the AccountNotFound returned by GetAccountInfo only tells you that the display name does not exist at that very moment, there is a time gap between calling GetAccountInfo and UpdateUserTitleDisplayName. The display name could be taken by other players in this gap. It would be better to handle both errors, and when NameNotAvailable occurs, you also prompt the user to pick another name.

Please note that when calling the GetAccountInfo API providing TitleDisplayName, if the non-unique Title Display Names option is enabled for the title, attempts to look up users by Title Display Name will always return AccountNotFound.

The way to catch the error varies in different SDKs. Could you please tell me which SDK do you use?

3 comments
10 |1200

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

MoonHeonYoung avatar image MoonHeonYoung commented ·

Thank you! This is the most wanted answer

I am using unity sdk.

Basically, I know how to call the client API, but I don't know how to capture and handle errors. Can you tell me a code sample?

NameNotAvailable / AccountNotFound

PlayFabClientAPI.UpdateUserTitleDisplayName

(new UpdateUserTitleDisplayNameRequest { DisplayName = "" }

, result => {},

error => {}); << I think this

0 Likes 0 ·
Rick Chen avatar image Rick Chen ♦ MoonHeonYoung commented ·

An example of handling error in unity is:

PlayFabClientAPI.UpdateUserTitleDisplayName(
            new UpdateUserTitleDisplayNameRequest { DisplayName = "your display name" },
            (UpdateUserTitleDisplayNameResult result)=> { 
                // your logic
            },
            (PlayFabError error)=> {
                if (error.Error == PlayFabErrorCode.NameNotAvailable)
                {
                    Debug.Log("Name is already taken, please pick another name");
                    //your logic
                }
            });

Modules used:

using PlayFab;
using PlayFab.ClientModels;

You could fill in with your error handling logic and put this function after the client login code.

0 Likes 0 ·
MoonHeonYoung avatar image MoonHeonYoung Rick Chen ♦ commented ·

Thank you for answer. Is the AccountNotFound error code check the same structure? Then I think I can do it.

0 Likes 0 ·

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.