Microsoft Azure PlayFab logo
    • Multiplayer
    • LiveOps
    • Data & Analytics
    • Add-ons
    • For Any Role

      • Engineer
      • Designer
      • Executive
      • Marketer
    • For Any Stage

      • Build
      • Improve
      • Grow
    • For Any Size

      • Solo
      • Indie
      • AAA
  • Runs on PlayFab
  • Pricing
    • Blog
    • Forums
    • Contact us
  • Sign up
  • Sign in
  • Ask a question
  • Spaces
    • PlayStream
    • Feature Requests
    • Add-on Marketplace
    • Bugs
    • API and SDK Questions
    • General Discussion
    • LiveOps
    • Topics
    • Questions
    • Articles
    • Ideas
    • Users
    • Badges
  • Home /
  • General Discussion /
avatar image
Question by dan · Oct 31, 2017 at 07:17 PM · CloudScriptPlayer Inventory

Having trouble with CloudScript and server.GrantItemsToUsers

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

Comment

People who like this

0 Show 0
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by Brendan · Nov 01, 2017 at 01:13 AM

The issue is that inventory item instances can only have 5 Key/Value pairs in custom data. Custom data has to be fairly limited in item instances, as a player could have thousands of items, depending on the title's tier.

Comment
dan

People who like this

1 Show 4 · Share
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image dan · Nov 01, 2017 at 10:25 AM 0
Share

Thanks for the info - that's super good to know! I had a sneaky suspicion that might have been the case...


You might want to add that information to...

a) The documentation for Server.Models.ItemGrant

b) The error message thrown up by adding too many keys.

c) The back end UI, where it is actually possible to add multiple keys.

d) All of the above

:)

2017-11-01-06-17-02-dans-android-phone-59fce1ad1a8.png (43.7 kB)
avatar image Brendan ♦♦ dan · Nov 01, 2017 at 09:48 PM 1
Share

Yes, I've filed a bug to get make that clearer, no worries. :)

avatar image Brendan ♦♦ Brendan ♦♦ · Nov 01, 2017 at 09:57 PM 1
Share

Oh, though I should point out that the error message actually does give you that data. If you return the full error message via a try/catch, or just call the API directly (via Postman, etc.), you'll see that the complete error response is:

{
    "code": 400,
    "status": "BadRequest",
    "error": "InvalidParams",
    "errorCode": 1000,
    "errorMessage": "Invalid input parameters",
    "errorDetails": {
        "Data": [
            "Too many keys specified in Data dictionary update. Limit is 5 and request contained 7."
        ]
    }
}

When you get an error in a Cloud Script though the exception returned can only contain the first part of that - best to use try/catch for debugging, so that you can get all the info.

avatar image dan · Nov 02, 2017 at 01:16 AM 0
Share

Thanks! JavaScript is not my specialty... that's good to know. :)

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Navigation

Spaces
  • General Discussion
  • API and SDK Questions
  • Feature Requests
  • PlayStream
  • Bugs
  • Add-on Marketplace
  • LiveOps
  • Follow this Question

    Answers Answers and Comments

    2 People are following this question.

    avatar image avatar image

    Related Questions

    Setting the currency of a player to an existing statistic? 1 Answer

    Granting items to user with custom data - item instance data 1 Answer

    Minify data sent from Azure Functions - Cloudscript too large 1 Answer

    Setting the currency of a player to a specific statistic value? 1 Answer

    Time Locked Items 3 Answers

    PlayFab

    • Multiplayer
    • LiveOps
    • Data & Analytics
    • Runs on PlayFab
    • Pricing

    Solutions

    • For Any Role

      • Engineer
      • Designer
      • Executive
      • Marketer
    • For Any Stage

      • Build
      • Improve
      • Grow
    • For Any Size

      • Solo
      • Indie
      • AAA

    Engineers

    • Documentation
    • Quickstarts
    • API Reference
    • SDKs
    • Usage Limits

    Resources

    • Forums
    • Contact us
    • Blog
    • Service Health
    • Terms of Service
    • Attribution

    Follow us

    • Facebook
    • Twitter
    • LinkedIn
    • YouTube
    • Sitemap
    • Contact Microsoft
    • Privacy & cookies
    • Terms of use
    • Trademarks
    • Safety & eco
    • About our ads
    • © Microsoft 2020
    • Anonymous
    • Sign in
    • Create
    • Ask a question
    • Create an article
    • Post an idea
    • Spaces
    • PlayStream
    • Feature Requests
    • Add-on Marketplace
    • Bugs
    • API and SDK Questions
    • General Discussion
    • LiveOps
    • Explore
    • Topics
    • Questions
    • Articles
    • Ideas
    • Users
    • Badges