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.
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.
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.
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?
Answer by Vladimir Razumov · Sep 26, 2019 at 04:04 PM
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.
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.
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.
Answer by Jacky Chou · Apr 06 at 03:23 AM
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