I use the following cloud script to add virtual currency(GO) to a user's PlayFab account. I get no error message in the client code and Console.WriteLine("Added reward!"); is executed, but Playstream always shows FAILED and the user's virtual currency doesn't get the increment.
Do you know what is wrong?
My cloud script:
handlers.AddGoldCoins = function (args, context) { if (args.rewardType == "Bronze") { server.AddUserVirtualCurrency({PlayFabID: currentPlayerID, VirtualCurrency: "GO", Amount: "100"}); } if (args.rewardType == "Silver") { server.AddUserVirtualCurrency({PlayFabID: currentPlayerID, VirtualCurrency: "GO", Amount: "200"}); } if (args.rewardType == "Gold") { server.AddUserVirtualCurrency({PlayFabID: currentPlayerID, VirtualCurrency: "GO", Amount: "500"}); } return {messageValue: "added reward"}; }
Client code:
private async Task AddVirtualCurrency() { var result = await PlayFabClientAPI.ExecuteCloudScriptAsync(new ExecuteCloudScriptRequest() { FunctionName = "AddGoldCoins", FunctionParameter = new { rewardType = "Bronze" }, GeneratePlayStreamEvent = true }); if (result.Error != null) { Console.WriteLine(result.Error.GenerateErrorReport()); } else { Console.WriteLine("Added reward!"); } }
In Playstream, I get this error message:
Player executed Cloud Script FAILED: AddGoldCoins() (revision 6)
Raw event JSON { "EventName": "player_executed_cloudscript", "Source": "CloudScript", "FunctionName": "AddGoldCoins", "CloudScriptExecutionResult": { "FunctionName": "AddGoldCoins", "Revision": 6, "FunctionResult": null, "FunctionResultTooLarge": null, "Logs": [], "LogsTooLarge": null, "ExecutionTimeSeconds": 0.0004205, "ProcessorTimeSeconds": 0, "MemoryConsumedBytes": 28088, "APIRequestsIssued": 0, "HttpRequestsIssued": 0, "Error": { "Error": "JavascriptException", "Message": "JavascriptException", "StackTrace": "ReferenceError: currentPlayerID is not defined\n at handlers.AddGoldCoins (BFD0A-main.js:6:49)" } }, "EventNamespace": "com.playfab", "EntityType": "player", "TitleId": "BFD0A", "EntityId": "4BDFD55D07F2D3F6", "EventId": "b2504b4f8a924b8b94d7724b27508669", "SourceType": "BackEnd", "Timestamp": "2019-05-30T22:19:05.8230987Z", "History": null, "CustomTags": null, "Reserved": null, "PlayFabEnvironment": { "Vertical": "master", "Cloud": "main", "Application": "logicserver", "Commit": "9ebcb67" } }