question

scottbinter avatar image
scottbinter asked

Getting Error on CloudScript 'Get Player Profile' after Account Creation?

We're setting up a cloudscript to retrieve location data from a player login/account creation and make it available in player publisher data. We only need the most recent location and have been having trouble getting it set up properly.

Initially we had a rule that on login we would migrate the data, but as one might expect this opened us up to a race condition between playfab and our data pull-down.

Later we attempted to modify this to manually run a cloud script function as soon as the login resolved correctly. The function involves the following call:

    var profile = server.GetPlayerProfile( {PlayFabId: currentPlayerId, ProfileConstraints: {ShowLocations: true}} );
  regInfo["LatestLocation"] = JSON.stringify(profile.PlayerProfile.Locations[0]);

Unfortunately it appears we have a similar issue. Sometimes the GetPlayerProfile call, despite having the login occur and resolve, hits a null profile 'Profile not found' error when logging in as a first-time-user.

In regards to this post (https://community.playfab.com/questions/19784/new-user-playfabclientapigetplayercombinedinfo-inf.html) it is suggested to sleep the invocation, but that's not really ever an airtight solution.

Is there no way to enforce completion of the player profile before the call? We were expecting that an account creation would return correctly once a player was created and anticipated that this would include the creation of a profile. For our use case we need to be able to guarantee a location pull.

Player DataCloudScript
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

·
Seth Du avatar image
Seth Du answered

If you are looking for “most recent location”, I believe you may monitor “player_logged_in” event ,where location information already contains in the context. If it is a Rule triggered Cloud Script function, you can get it via context.playStreamEvent.Location.

Otherwise, you may try to monitor “player_added_title” event instead of “player_created” or “entity_created” events. I have tested it and it works fine for me.

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

scottbinter avatar image scottbinter commented ·

Thank you for your response! We had previously been monitoring that event via a rule. Unfortunately sometimes this was not fast enough and presented a race condition. If the server had not activated the rule by the time we requested the location, we would get either null, if the account was new, or the last logged in location if the account was previously created.


We attempted to get an event from the context but that turned out to be null - and we could find no documented way of doing so. Experimentation did not work out in our favor, but if you know of a way to carry an event with a manual invocation of a cloud script that would be an amazing solution.

0 Likes 0 ·
Seth Du avatar image Seth Du ♦ scottbinter commented ·

I find more information about this issue. The "Profile" won't be generated immediately after a player is initially generated if there is no other actions done by this player. It seems to be by design, and I believe there should be work around solutions. If you want to get location information, I believe it will be better to retrieve it from the contents inside logged-in related PlayStream Event and store it into Player Read-Only/Internal Data for late use. I am not sure why yours is null but I in my testing scenarios, I cannot reproduce it.

0 Likes 0 ·
scottbinter avatar image scottbinter Seth Du ♦ commented ·

Are you storing that data as part of a rule? We need to manually invoke the call as part of a promise chain, so unfortunately we can't use an automated response-rule. We're trying to institute determinism everywhere possible after finding some data inaccuracies/latency.

0 Likes 0 ·
Seth Du avatar image Seth Du ♦ scottbinter commented ·

I believe I haven't fully understand the scenario and I thought you are trying to monitor the player's location automatically via Rules, but there was null in the response. I am providing solutions to fix the "null" issue.

To sum it up, you can get location information from two sources, Player Profile and PlayStream Event. Location in profile cannot be promised to be the latest, because Profile itself is not updated immediately. There is latency of few seconds. Meanwhile, PlayStream Event is promised to be up-to-date.

0 Likes 0 ·
Seth Du avatar image Seth Du ♦ scottbinter commented ·

>>Are you storing that data as part of a rule?

I create a Rule, that is triggered by "player_logged_in" event and Action Type is "Execute Cloud Script", where it only runs a sentence:

log.info(context.playStreamEvent.Location.City);

"context" is from the "player_logged_in" event and if you check this event in Game Manager, there is a property named Location, which will be like:

    "Location": {
        "ContinentCode": "AS",
        "CountryCode": "JP",
        "City": "xxxxx",
        "Latitude": xxxx,
        "Longitude": xxxx
    },

And the city name is printed out in the Cloud Script succesfully, which mean you can call any API to use the data, like UpdateUserData to make it be exposed to other players.

0 Likes 0 ·
scottbinter avatar image scottbinter Seth Du ♦ commented ·

The issue we've had is that rules have no determinism guarantee. It's entirely possible to create a rule that moves data form player_logged_in and it will not execute in time. We have no way of receiving a callback from the rule.

Manual triggering a cloud script function does not appear to come bundled with a playstream event to consult despite attempting to include one. I cannot find any examples or documentation that include this.

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.