question

comofficialakhter007 avatar image
comofficialakhter007 asked

Set Player Initial level as 1.

Trying to set Initial Player level as 1. But getting error. Need Help!

CLOUD SCRIPTS:

 handlers.SetInitialLevel = function(args, context){
     var createLevelData = {
         PlayerId: currentPlayerId,
         Data: {}
     }
     createLevelData.Data["level"] = 0;
    
     var createLevelResult = server.UpdateUserInternalData(JSON.stringify(createLevelData.Data));
     return createLevelResult;
 }

//--------------------------------------------------------------------------------------------------------------------------------------

//-------------------------------------------------------------------------------------------------------------------------------------- UNIT C SARP CODE:

     void SetPlayerLevel(){
    
         var request = new ExecuteCloudScriptRequest{
             FunctionName = "SetInitialLevel"
         };
         PlayFabClientAPI.ExecuteCloudScript(request, OnLevelCreated, OnError);
    
     }
    
    
     void OnLevelCreated(ExecuteCloudScriptResult result){
         Debug.Log(JsonUtility.ToJson(result));
     }

//--------------------------------------------------------------------------------------------------------------------------------------

I am calling this method On Login Success

ERROR

{"APIRequestsIssued":1,"Error":{"Error":"CloudScriptAPIRequestError","Message":"The script called a PlayFab API, which returned an error. See the Error logs for details.","StackTrace":"Error\n at Object.server_request (Script:181:24)\n at server.UpdateUserInternalData (Script:629:79)\n at handlers.SetInitialLevel (C5E75-main.js:9:36)\n at Object.invokeFunction (Script:117:33)"} ,

CloudScript
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

·
Xiao Zha avatar image
Xiao Zha answered

As you can see in the Player Data Management - Update User Internal Data - REST API (PlayFab Server) | Microsoft Learn, you may change the “PlayerId” in your code to “PlayFabId”. You may also need to put the entire “createLevelData” instead of “createLevelData.Data” into the API request. Below is the working code you may refer to.

 handlers.SetInitialLevel = function(args, context) {
     var createLevelData = {
         PlayFabId: currentPlayerId,
         Data: {}
     };
     createLevelData.Data["level"] = 0;
    
     var createLevelResult = server.UpdateUserInternalData(createLevelData);
     return createLevelResult;
 };
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.