Is it normal that the title display name changes to "undefined" if creating/updating the display name fails in CloudScript?
I had a JavascriptException in my CloudScript and after that the title display name changed to undefined.
Will the title display name always change to undefined if something goes wrong with creating/updating the title display name?
Raw event JSON { "EventName": "player_executed_cloudscript", "Source": "CloudScript", "FunctionName": "VerifyText", "CloudScriptExecutionResult": { "FunctionName": "VerifyText", "Revision": 62, "FunctionResult": null, "FunctionResultTooLarge": null, "Logs": [ { "Level": "Info", "Message": "Display name changed", "Data": null } ], "LogsTooLarge": null, "ExecutionTimeSeconds": 0.10228119999999999, "ProcessorTimeSeconds": 0, "MemoryConsumedBytes": 73296, "APIRequestsIssued": 1, "HttpRequestsIssued": 1, "Error": { "Error": "JavascriptException", "Message": "JavascriptException", "StackTrace": "TypeError: Cannot read property 'toString' of undefined\n at Object.handlers.UpdateDisplayname (BFD0A-main.js:109:36)\n at handlers.VerifyText (BFD0A-main.js:176:18)" } }, "EventNamespace": "com.playfab", "EntityType": "player", "TitleId": "BFD0A", "EntityId": "1066CF1F71C39EC1", "EventId": "095c9614065b4385bbbc3b235a14f2a5", "SourceType": "BackEnd", "Timestamp": "2019-10-10T08:22:51.0393116Z", "History": null, "CustomTags": null, "Reserved": null, "PlayFabEnvironment": { "Vertical": "master", "Cloud": "main", "Application": "logicserver", "Commit": "a881f0a" } }
Raw event JSON { "EventName": "player_displayname_changed", "PreviousDisplayName": null, "DisplayName": "undefined", "EventNamespace": "com.playfab", "EntityType": "player", "Source": "PlayFab", "TitleId": "BFD0A", "EntityId": "1066CF1F71C39EC1", "EventId": "52863f8713d945f6acc4393c3f8e480a", "SourceType": "BackEnd", "Timestamp": "2019-10-10T08:22:51.0230004Z", "History": null, "CustomTags": null, "Reserved": null, "PlayFabEnvironment": { "Vertical": "master", "Cloud": "main", "Application": "mainserver", "Commit": "a881f0a" } }
UPDATE:
I call VerifyText in my client code and I found out that I don't get the JavascriptException if I change handlers.UpdateDisplayname = function (args, context) to function UpdateDisplayname(NewDesiredDisplayname).
In addition, now the title display name doesn't change to "undefined" if I create/update it. Now, title display name has the correct string.
handlers.VerifyText = function (args, context) { if (VerifyTextLength(args.text) && VerifyTextASCII(args.text)) { UpdateDisplayname(args.text); // handlers.UpdateDisplayname(args.text,context); log.info(args.text); return "true"; } else { if (!VerifyTextLength(args.text) && !VerifyTextASCII(args.text)) { log.info(args.text); return "too long and characters are not supported"; } else { if (!VerifyTextLength(args.text)) { log.info(args.text); return "too long"; } if (!VerifyTextASCII(args.text)) { log.info(args.text); return "characters are not supported"; } } } } function VerifyTextLength(text) { if (text.length <= 20) { return true; } else { return false; } } function VerifyTextASCII(text) { var notSupportArray = new Array(); for (var i = text.length - 1; i >= 0; i--) { var charCode = text.charCodeAt(i); if ((charCode >= 32 && charCode <= 512) || (charCode >= 8216 && charCode <= 8222) || (charCode >= 8352 && charCode <= 8378)) { } else { notSupportArray.push(charCode); } } if (notSupportArray.length == 0) { return true; } else { return false; } } //handlers.UpdateDisplayname = function (args, context) function UpdateDisplayname(NewDesiredDisplayname) { // var NewDisplayname = args.DesiredDisplayname; var NewDisplayname = NewDesiredDisplayname; var CurrentDisplayName = ""; var resultprofile = server.GetPlayerProfile( { PlayFabID: currentPlayerId, ProfileConstraints : { ShowDisplayName: true } }); if (resultprofile.Error == null) { if (resultprofile.PlayerProfile != null) { CurrentDisplayName = resultprofile.PlayerProfile.DisplayName; if ((CurrentDisplayName == null) || (CurrentDisplayName == "")) { var result = UpdateUserTitleDisplayNameFromCloudScript(NewDisplayname, currentPlayerId); if (result.error == "NameNotAvailable") { log.info("This display name already exists: " + NewDisplayname.toString() + " Please choose another display name"); return "display name already exists"; } if (result.error == "InvalidParams") { log.info("The Display name must be a string with a minimum length of 3 and a maximum length of 20."); return "Invalid Parameters"; } log.info("Display name changed"); return NewDisplayname.toString(); } else log.info("You already have a display name. It's not possible to change it:" + CurrentDisplayName.toString()); } } } function UpdateUserTitleDisplayNameFromCloudScript(DesiredDisplayname, PlayFabId) { var contentBodyTemp = { "DisplayName": DesiredDisplayname, "PlayFabId": PlayFabId }; let url = "https://BFD0A.playfabapi.com/Admin/UpdateUserTitleDisplayName"; let method = "POST"; let contentBody = `{"PlayFabId": "${PlayFabId}", "DisplayName": "${DesiredDisplayname}"}`; let contentType = "application/json"; let headers = { "X-SecretKey": "..." }; let responseString = http.request(url, method, contentBody, contentType, headers); let responseJSONObj = JSON.parse(responseString); return (responseJSONObj); }