question

terrypapamarkou avatar image
terrypapamarkou asked

delete current player

I have a debug button in my game that I am trying to get to delete the current playfab player and reload the game. I'm calling Server/DeletePlayer from a cloud script and I have enabled player deletion in the game manager. I've tried a bunch of different things but I just keep getting these errrors.

The script made an external HTTP request, which returned an error.

HTTP request error

handlers.DeletePlayfabPlayerForTesting = function (args, context) {
   
	
	var contentType = "application/json";
	var header = JSON.stringify
	({
		"Content-Type":"application/json",
		"X-SecretKey":"mykey"
	});
 
 
	var body = JSON.stringify
	({


		"PlayFabId":currentPlayerId
	});
 	log.debug("body "+ body);
	log.debug("header "+ header);
	var response = http.request("https://mytitle.playfabapi.com/Server/DeletePlayer", "POST", body, contentType, header);
	
    return {
        Result: "success"
    };
};

Is there an obvious error there? Is it possible to delete the player calling the cloudscript?

Thanks

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 answered

If you are using cloud script, please note that cloud script is implemented with PlayFab API, which means there is no need to manually craft a HTTP call. You may refer to my code:

handlers.DeletePlayfabPlayerForTesting = function (args, context) { 
var request =  
{ 
"PlayFabId":currentPlayerId 
}; 
var response = server.DeletePlayer(request);

};

Moreover, if crafting an HTTP request call is necessary in your cloud script, please write debug sentences that can return detailed response messages, especially the error message.

1 comment
10 |1200

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

terrypapamarkou avatar image terrypapamarkou commented ·

Thank you very much. I did try using server.DeletePlayer first but I must have had something wrong with my code. Yours worked. Thanks again.

0 Likes 0 ·
elaine avatar image
elaine answered

@SethDu

Hi, may I know how to show the response on Unity C# script please ?

    public void HandleDeleteAccount()
    {
        var request = new ExecuteCloudScriptRequest
        {
            FunctionName = "deletePlayer"
        };

        PlayFabClientAPI.ExecuteCloudScript(request, OnExecuteSucess, OnError);


    }


    void OnExecuteSucess(ExecuteCloudScriptResult result)
    {
        Debug.Log(result.ToString());
    }

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.