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 kylemukundi · Oct 26, 2020 at 09:38 PM · apisunity3dAccount Management

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?

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 Paul Boutros · Oct 27, 2020 at 01:15 AM

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

Comment

People who like this

0 Show 2 · 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 kylemukundi · Oct 28, 2020 at 02:14 PM 0
Share

I login with email address and password

avatar image kylemukundi · Oct 28, 2020 at 03:05 PM 0
Share

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.

avatar image

Answer by SethDu · Oct 27, 2020 at 05:15 AM

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

}

Comment
kylemukundi

People who like this

1 Show 0 · 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

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

    How can I convert the timezone in PlayFab? 1 Answer

    UserData object different between client and server? 1 Answer

    Removal of GMS dependency 1 Answer

    AddUsernamePassword requires both email and username while Other APIs do not? 1 Answer

    Unable to update PlayFab Unity SDK 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