HI there,
I am seeing some weird behavior when trying to call server.GrantItemsToUsers with CloudScript.
To give you a little background, I am creating a turn-based multiplayer game, and am adding "game" to the players' inventories to keep track of the matches they have on the go. I have a Photon callback that adds these games on room creation.
The following code works beautifully....
//Create an array for the Item Grants var games = []; for(var i = 0; i < args.CreateOptions.ExpectedUsers.length; i++) { //var accepted = new Boolean(args.CreateOptions.ExpectedUsers[i]===args.UserId); games.push({ "PlayFabId": args.CreateOptions.ExpectedUsers[i], "ItemId": "Game", "Data": { "Sender": args.UserId, "GameID": args.GameId, "Players": args.CreateOptions.MaxPlayers.toString(), "PlayerIDs": args.CreateOptions.ExpectedUsers.toString(), "GameOver": false.toString() } }) } //For Debugging purposes server.SetTitleData({ Key: "Games", Value: JSON.stringify(games) }); //Send the games server.GrantItemsToUsers({ "CatalogVersion": "RFI", "ItemGrants": games });
Giving me the following JSON data for the itemGrants...
[ { "PlayFabId": "59FCE1AD1A872162", "ItemId": "Game", "Data": { "Sender": "59FCE1AD1A872162", "GameID": "262334043389", "Players": "2", "PlayerIDs": "59FCE1AD1A872162,2B4680FC09C32C7", "GameOver": "false" } }, { "PlayFabId": "2B4680FC09C32C7", "ItemId": "Game", "Data": { "Sender": "59FCE1AD1A872162", "GameID": "262334043389", "Players": "2", "PlayerIDs": "59FCE1AD1A872162,2B4680FC09C32C7", "GameOver": "false" } } ]
However, if I try and add any more keys, the function stops working. For example, the code below contains one extra data key, ResultSeen...
//Create an array for the Item Grants var games = []; for(var i = 0; i < args.CreateOptions.ExpectedUsers.length; i++) { //var accepted = new Boolean(args.CreateOptions.ExpectedUsers[i]===args.UserId); games.push({ "PlayFabId": args.CreateOptions.ExpectedUsers[i], "ItemId": "Game", "Data": { "Sender": args.UserId, "GameID": args.GameId, "Players": args.CreateOptions.MaxPlayers.toString(), "PlayerIDs": args.CreateOptions.ExpectedUsers.toString(), "GameOver": false.toString(), "ResultSeen": false.toString() } }) } //For Debugging purposes server.SetTitleData({ Key: "Games", Value: JSON.stringify(games) }); //Send the games server.GrantItemsToUsers({ "CatalogVersion": "RFI", "ItemGrants": games });
...and produces the following JSON data, all well and good...
[ { "PlayFabId": "59FCE1AD1A872162", "ItemId": "Game", "Data": { "Sender": "59FCE1AD1A872162", "GameID": "262337976668", "Players": "2", "PlayerIDs": "59FCE1AD1A872162,2B4680FC09C32C7", "GameOver": "false", "ResultSeen": "false" } }, { "PlayFabId": "2B4680FC09C32C7", "ItemId": "Game", "Data": { "Sender": "59FCE1AD1A872162", "GameID": "262337976668", "Players": "2", "PlayerIDs": "59FCE1AD1A872162,2B4680FC09C32C7", "GameOver": "false", "ResultSeen": "false" } } ]
...but the room fails to initialise, throwing up the following warning in Unity...
Operation 227 failed in a server-side plugin.Check the configuration in the Dashboard. Message from server-plugin: Failed to create game on https://B433.playfablogic.com/webhook/1/prod/7EXAQPX4BWIK11YN6N8TUGD6O3CN6594C4AZFFBFMFYUFRYRBO/RoomCreated? : Error response ResultCode='4' Message='PlayFabAPIError InvalidParams: Invalid input parameters at __playfab_internal_v1.server_request (Script Document:36:13) -> throw apiResult; at server.GrantItemsToUsers (Script Document:554:74) at handlers.RoomCreated (B433-main.js:135:10) at __playfab_internal_v1.invokeHandler (Script Document:20:22)'. UnityEngine.Debug:LogError(Object) NetworkingPeer:OnOperationResponse(OperationResponse) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:1559) ExitGames.Client.Photon.PeerBase:DeserializeMessageAndCallback(Byte[]) ExitGames.Client.Photon.EnetPeer:DispatchIncomingCommands() ExitGames.Client.Photon.PhotonPeer:DispatchIncomingCommands() PhotonHandler:Update() (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonHandler.cs:157)
Does anyone have any idea what I am doing wrong? This is driving me nuts!
Thanks in advance for your help!
Cheers,
Dan