question

luke1513 avatar image
luke1513 asked

I need help with a system that adds virtual currency, somehow it doesn't work.

First of all, I am a beginner. Its my first system ever written. Every 10 seconds it validates the value and updates the virtual currency if the value is in an acceptable range. In the unity console it says "null" after the call is completed. If i refresh the virtual currency tab of the player it's still 200, the initial value.

CloudScript:

handlers.Validate = function(args, context) {

if(args && args.hasOwnProperty("inputValue")) {

var currentValue = args.inputValue;

if(currentValue <= 300) {

server.AddUserVirtualCurrency({ PlayFabId: currentPlayerID, VirtualCurrency: CA, Amount: currentValue });

var inventory = server.GetUserInventory({ PlayFabId: currentPlayerId });

var finalValue = inventory.VirtualCurrency.CA;

return { value: finalValue }; }

else return { messageValue: "Cheater Detected!" };

}

}

Unity:

void ValidateValues() {

PlayFabClientAPI.ExecuteCloudScript(new ExecuteCloudScriptRequest() {

FunctionName = "Validate", FunctionParameter = new { inputValue = Stats.currentCAAmount }, GeneratePlayStreamEvent = true }, result => Debug.Log(result.FunctionResult), error => Debug.Log(error.GenerateErrorReport())

);}

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

1. There is a syntax error in your Cloud Script code (currentPlayerId and "CA"), please correct it like this:

server.AddUserVirtualCurrency(
	{
		PlayFabId: currentPlayerId,
		VirtualCurrency: "CA", 
		Amount: currentValue 
	}
);

2. Make sure the Cloud Script function you implemented is in a LIVE Cloud Script revision, and you can also use a specific revision via adding two properties in your request:

RevisionSelection = CloudScriptRevisionOption.Specific,

SpecificRevision = 31 /* your revision number */

Please find more details on documentation website: https://docs.microsoft.com/zh-cn/rest/api/playfab/client/server-side-cloud-script/executecloudscript?view=playfab-rest

3. I have noticed that you set GeneratePlayStreamEvent as true, and this step is important because you can see what happened after executing Cloud Script. Navigating to [Game Manager] -> [Dashboard] -> [PlayStream Monitor] will help you locate the error, if you failed to execute the Cloud Script, there will be an event like:

Clicking the button on the right top corner will show you the detailed information:

As you can see one of your error is that CA should be a String in the request.

For more information, you can also refer to: https://docs.microsoft.com/zh-cn/gaming/playfab/features/automation/cloudscript/handling-errors-in-cloudscri


    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.

    luke1513 avatar image luke1513 commented ·

    @SethDu Thanks for the detailed answer, i appreciate your help a lot. I will definitely use playstream events for debugging in the future. I am sorry for my pathetic beginner mistakes, haha.

    1 Like 1 ·

    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.