question

Timurs Sugajevs avatar image
Timurs Sugajevs asked

currentPlayerId is different with every entity cloud script call

PlayFabCloudScriptAPI.ExecuteEntityCloudScript(new ExecuteEntityCloudScriptRequest()
    {
        FunctionName = "TestId",
    },
    (res) =>
    {
        Debug.Log(res);
    },
    res =>
    {
        Debug.Log(res);
    });
handlers.TestId = function (args, context)
{
  var entityProfile = context.currentEntity;  
  log.info(currentPlayerId);
  log.info(entityProfile.Entity);
}

First - my client (Unity) code. Second - my cloud script function. entityProfile.Entity is the same every call (it's my entity), but currentPlayerId -is different all the time and belongs to another random player.

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

Seth Du avatar image Seth Du ♦ commented ·

When a player creates a player account, a master player account will be firstly created, then according to the title, a title player account under this master player account will be created. It means a player will have 2 ID. Title ID is unique in a title, master player ID is PlayFab ID, which is studio-unique.


When you make use of entity IDs, please also refer its entity type. If you review the full response of login APIs, both master account ID(PlayFab ID) and title ID are returned.

0 Likes 0 ·
Timurs Sugajevs avatar image Timurs Sugajevs Seth Du ♦ commented ·

I understand this, but how is it connected with my question? When I call

PlayFabClientAPI.ExecuteCloudScript(new ExecuteCloudScriptRequest()
    {
        FunctionName = "TestId",
    },
    (res) =>
    {
        Debug.Log(res);
    },
    res =>
    {
        Debug.Log(res);
    });

I receive log where currentPlayerId is always my playfabId. And when i use ExecuteEntityCloudScript function currentPlayerId is different every call. I call those function being logged.

0 Likes 0 ·
Seth Du avatar image Seth Du ♦ Timurs Sugajevs commented ·

I have tested your code, if I directly print out currentPlayerId, it will throw a not-defined error and if it is context.currentPlayerId, this parameter is blank.

Have you set a global variable in your script?

-1 Like -1 ·
Timurs Sugajevs avatar image
Timurs Sugajevs answered

I didn't define currentPlayerId by myself. it's a global variable, that described for example there https://api.playfab.com/documentation/server/method/ExecuteCloudScript . There is no api documentation for ExecuteEntityCloudScript from client, but I assume that this variable should be defined by server too. I don't know about context.currentPlayerId. I did not see mentions in docs and tutorials. Your test's results are very strange and looks like another bug as well.

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.

Seth Du avatar image Seth Du ♦ commented ·

May I have your title ID and revision number?

0 Likes 0 ·
Timurs Sugajevs avatar image Timurs Sugajevs Seth Du ♦ commented ·

4F51, last revision(217)

Right now in some functions currentPlayerId is defined from args. But currently I don't use those functions. And TestId functions results is always random with these functions in revision and without.

0 Likes 0 ·
Seth Du avatar image Seth Du ♦ Timurs Sugajevs commented ·

I have written a testing project to call ExecuteEntityCloudScript in a loop and the result is in the most of the case, it returns not-defined error and there are 1-3 cases return the correct ID every 20 times. We assume it to be a potential bug and will file it. I will keep you informed when there is feedback from our team.

PS. execute cloud script API will return success in most of the cases because the execution action is done successfully meanwhile even error is returned in the function, the status for API is successful, hence, we may need to check what is inside the onSuccess callbacks.

0 Likes 0 ·
Jacky Chou avatar image
Jacky Chou answered

@SethDu @Vladimir Razumov

Hello, I am having the same problem. currentPlayerId is different every time the same client call a legacy cloudscript entity function. How was this problem solved?

Title id: B3B88. Revision: 1225

10 |1200

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

Jacky Chou avatar image
Jacky Chou answered

It seemed only happen in live revision

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.

Error rendering WebPanel (widgets/consolidation-widget.ftl): org.hibernate.hql.internal.ast.QuerySyntaxException: AvailableConsolidation is not mapped [from AvailableConsolidation up where up.node = :node]