I get an error message in my cloudScript but I don't know what I'm doing wrong.
SyntaxError: Unexpected token void at Script Document [3]:7:12 -> public void ChooseanAvatar(String avatarnumber)
What is wrong with my cloudScript?
I only want to allow my avatars in my game: https://community.playfab.com/questions/33775/i-only-want-to-allow-my-avatars-in-my-game.html?childToView=33803#comment-33803
My CloudScript:
handlers.UpdatePlayerAvatar = function (args, context) { var AvatarNumber = args.DesiredAvatar; var CurrentAvatarUrl = ""; var NewAvatarUrl = ""; public void ChooseanAvatar(String avatarnumber) { switch (avatarnumber) { case "0": NewAvatarUrl = "https://banner2.kisspng.com/20171216/b7c/bart-simpson-png-5a357766c9ce48.7360387215134534148266.jpg"; break; case "1": NewAvatarUrl = "https://cdn.imgbin.com/12/23/1/imgbin-bart-simpson-homer-simpson-lisa-simpson-skateboard-bart-simpson-illustration-ejAZuguU5kURKYmP6L9Yp47s7.jpg"; break; case "2": NewAvatarUrl = "https://www.stickpng.com/assets/thumbs/5a0c40785a997e1c2cea1168.png"; break; } } var resultprofile = server.GetPlayerProfile( { PlayFabID: currentPlayerId, ProfileConstraints : { ShowAvatarUrl: true } }); if (resultprofile.Error == null) { if (resultprofile.PlayerProfile != null) { CurrentAvatarUrl = resultprofile.PlayerProfile.AvatarUrl; ChooseanAvatar(AvatarNumber); if ((NewAvatarUrl != "") && (NewAvatarUrl != CurrentAvatarUrl)) server.UpdateAvatarUrl({PlayFabId: currentPlayerId, ImageUrl: NewAvatar}); else log.info("Not possible to change Avatar:" + CurrentAvatarUrl.toString()); } } }
My client code:
private async Task UpdateAvatarUrl() { var result = await PlayFabClientAPI.ExecuteCloudScriptAsync(new ExecuteCloudScriptRequest() { FunctionName = "UpdatePlayerAvatar", FunctionParameter = new { DesiredAvatar = "1" }, GeneratePlayStreamEvent = true }); if (result.Error != null) Console.WriteLine(result.Error.Error.ToString()); else { if (result.Result.Logs.Count() > 0) Console.WriteLine(result.Result.Logs[0].Message); else Console.WriteLine("Your new Avatar: " + "1"); } }