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 /
  • General Discussion /
avatar image
Question by Canberk Soner · Sep 03, 2018 at 08:33 PM · CloudScriptPlayer DataPlayer Inventory

Best practice for getting user data and account info on login

Hello,

I want to do the following when a player logs:

-Add items and a default user data (if logging in for the first time)

-Get the account info

-Get user data

-Get inventory of player

I need all of these as we show user's display name in lobby (received in account info), some basic stats like level & xp (stored in userdata), and his equipped items in a 3d scene.

In another topic, it was suggested to use playstream events to add default items and user data, but I don't think that approach would work for me, since my client APİ calls and cloudscript function called by playstream event would not be synchronous.

What I got so far:

1) When login is successful, call a single cloudscript function from client. The function initializes inventory & basic data if it is first login(not sure how to check this in cloudscript). Then, it calls server API functions to get account info, user data and inventory, then returns them to the client in a single response. Not sure how to accomplish this part in cloudscript, though.

2) After a successful login, call a single cloudscript function that only initialized inventory & basic data if it is the first login. Then, use client API to get other necessary data from Playfab. Would making 3 simultaneous client API calls be a problem?

What would be the best approach here?

Comment
Burak Sen

People who like this

1 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

1 Reply

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by Brendan · Sep 03, 2018 at 09:11 PM

Your best bet would be to have an "OnLogin" Cloud Script that you call from the client after the login returns, and use it to request the data you need, as described in 2 (since you can get user data and stats from the client directly, there's no need to put that in the Cloud Script call). To determine if it's the player's first login, you could use any statistic that you track as part of your game - if the player has it, it's not their first login. Make sure to set the stat to a default value only at the end of setup, so that you can make sure everything else is complete first, of course.

The one caution is that if you're doing a lot of things for the player on start (it's a lot of inventory items, for example), you may need to stage this out over a short period of time, as it may be too much work for a single Cloud Script call. Alternately, if you're using custom game servers for multiplayer, you could also use them to process setup logic for new players by having the players matchmake into them and provide a distinct setup request (having the server check their statistics, to make sure they're new).

Simultaneous calls are usually not a good idea, since you have no way of determining in what order they'll be processed. If the three calls are completely distinct from one another - meaning there's zero overlap between the things they're reading/writing - then it should be fine.

Comment
Canberk Soner
Burak Sen

People who like this

2 Show 3 · 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 Canberk Soner · Sep 04, 2018 at 08:33 AM 0
Share

Thanks for the reply.

"Simultaneous calls are usually not a good idea, since you have no way of determining in what order they'll be processed. If the three calls are completely distinct from one another - meaning there's zero overlap between the things they're reading/writing - then it should be fine."

For me, order does not matter, I only need all of them to be completed, in whatever order. They would all be reading 3 different things, so as long as Playfab does not block simultaneous calls from a single client, it should be okay?

Another question is, what exactly is a simultaneous call? Same frame? Would waiting 1 frame between calls be enough?

In addition, would making the 3 simultaneous calls in cloudscript cause any issue? How limiting is the 1 second limit in this case, assuming we just read data from 3 api calls?

avatar image Brendan ♦♦ Canberk Soner · Sep 04, 2018 at 10:22 AM 0
Share

What frame you make a call on is irrelevant. Every Web API call is a call made over the internet, and is going to have unique latency, based on how it is routed. If you make a call to an endpoint, then make another one or two frames later, the second call could easily arrive at the endpoint before the first - there's literally no way to guarantee that short of waiting on the response from the first call. So the concept of "simultaneous" really means "without waiting on a response".

The issues you'll run into with backend services (through PlayFab or otherwise) are going to be if you issue multiple calls that could change the same data row multiple times without waiting on a response. The problem is that since you have absolutely no control over the delivery time of each packet, you cannot control the order in which they arrive. So if they affect the same row, the total change is indeterminate.

avatar image Canberk Soner Brendan ♦♦ · Sep 04, 2018 at 12:20 PM 0
Share

I understand. Thanks for your help.

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

    Granting items to user with custom data - item instance data 1 Answer

    Setting the currency of a player to an existing statistic? 1 Answer

    Setting the currency of a player to a specific statistic value? 1 Answer

    Performance PlayStream, CloudScript in Professional plan 1 Answer

    1 Day Trial Hero Card for MOBA Game Setup in PlayFab Catalog 1 Answer

    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