question

kylemukundi avatar image
kylemukundi asked

Is there a way to wait until login?

Hello. I have a script that logs in or prompts account register for a player. Is there a way to wait until the player is logged in or not so that when I make API calls from another script, it doesn't give me the "Must be logged in to call this method" error?

apisunity3dAccount Management
10 |1200

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

Paul Boutros avatar image
Paul Boutros answered

Well I suppose your API login call looks like :
PlayFabClientAPI.LoginWithCustomID(request, OnLogin, OnLoginError);
right? So you could have a public readonly bool variable in your OnLogin for example:
OnLogin(){
currentlyLoggedIn = true;
}
Your other script could run a coroutine that would do something like:
While( !myExampleLoginScript.currentlyLoggedIn ) {

//don't go further until myExampleLoginScript.currentlyLoggedIn
//is set to true

yield return null;
}

// when it finally is set to true
// Do the intended task here

2 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.

kylemukundi avatar image kylemukundi commented ·

I login with email address and password

0 Likes 0 ·
kylemukundi avatar image kylemukundi commented ·

Good answer! I set a bool to true when the player is logged in and then access it from whatever script that needs to make api calls.

0 Likes 0 ·
Seth Du avatar image
Seth Du answered

In some SDKs, like Unity SDK and C# SDK, APIs are capsuled as asynchronous tasks. Paul Boutros provides a feasible workaround, however, in the common scenario, we will add the following APIs in the callback result function. I will use Unity SDK and C# Action as an example:

PlayFabClientAPI.LoginWithCustomID(
    new PlayFab.ClientModels.LoginWithCustomIDRequest {
        TitleId = "xxxx",
        CreateAccount = true,
        CustomId = "xxxxxxx"
    },
    onSuccess => {

        print(PlayFabSettings.staticPlayer.ClientSessionTicket);

        PlayFabClientAPI.GetLeaderboard(
            // additional API calls
            
            );
    },
    onFailure=> {
        print(onFailure.GenerateErrorReport());
    });

}

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.