question

tboesch avatar image
tboesch asked

Cloudscript not executing GetUserInventoryRequest

First off I'd like to say that I am NOT very good at coding the CloudScript. I'm not used to the language and therefore am terrible at it. Don't laugh ;)

So what I'm looking to do ultimately is to have this kind of flow...

1) Player created

2) Create basic player data (level, exp, maxExp)

3) Set the default "equipped" inventory for the player

4) Set the player's avatar image

5) Give the "equipped" inventory from earlier useful stats.

However, everything goes great up until step 5. I don't get any kind of log statement saying that the request is even starting to be processed. I have linked my code below. What am I doing wrong?

handlers.CreateInitialPlayerData = function (args, context) {
	log.debug("Creating player data...");
  	
  	var request = {
      PlayFabId: currentPlayerId,
      Permission: "Public",
      Data: {"Level": "1",
            "Exp": "0",
            "MaxExp": "100"}
    };
    server.UpdateUserReadOnlyData(request);
  
  	var request2 = {
      PlayFabId: currentPlayerId,
      Permission: "Public",
      Data: {"DefaultSub": "Flounder",
            "DefaultCrew1": "Danny",
            "DefaultCrew2": "Matt",
            "DefaultCrew3": "Tyler"}
    };
  	server.UpdateUserData(request2);
  
  	var request3 = {
      PlayFabId: currentPlayerId,
      ImageUrl: "https://i.imgur.com/JwIujAf.png"
    }
    server.UpdateAvatarUrl(request3);
  
  	var getUserInventoryResult = server.GetUserInventory({PlayFabId: currentPlayerId});
  
  	for(var i = 0; i < getUserInventoryResult.Count; i++) {
    	if(getUserInventoryResult[i].Inventory.ItemId == "Danny") {
        	log.debug("Danny's Instance Id: " + getUserInventoryResult[i].Inventory.ItemInstanceId);
          	var request4 = {
	  			PlayFabId: currentPlayerId,
      			ItemInstanceId: getUserInventoryResult[i].Inventory.ItemInstanceId,
      			Data: {
      				"Navigation": "1",
        			"Weapons": "2",
        			"Engines": "3",
        			"Shields": "1"
      			}
    		};
			server.UpdateUserInventoryItemCustomData(request4);
          	log.debug("Updated Danny's custom data");
        }
    }
  
  	for(var i = 0; i < getUserInventoryResult.Count; i++) {
    	if(getUserInventoryResult[i].ItemId == "Matt") {
        	log.debug("Matt's Instance Id: " + getUserInventoryResult[i].ItemInstanceId);
          	var request5 = {
	  			PlayFabId: currentPlayerId,
      			ItemInstanceId: getUserInventoryResult[i].ItemInstanceId,
      			Data: {
      				"Navigation": "1",
        			"Weapons": "3",
        			"Engines": "2",
        			"Shields": "1"
      			}
    		};
			server.UpdateUserInventoryItemCustomData(request5);
          	log.debug("Updated Matt's custom data");
        }
    }
  
  	for(var i = 0; i < getUserInventoryResult.Count; i++) {
    	if(getUserInventoryResult[i].ItemId == "Tyler") {
        	log.debug("Tyler's Instance Id: " + getUserInventoryResult[i].ItemInstanceId);
          	var request6 = {
	  			PlayFabId: currentPlayerId,
      			ItemInstanceId: getUserInventoryResult[i].ItemInstanceId,
      			Data: {
      				"Navigation": "2",
        			"Weapons": "1",
        			"Engines": "1",
        			"Shields": "3"
      			}
    		};
			server.UpdateUserInventoryItemCustomData(request6);
          	log.debug("Updated Tyler's custom data");
        }
    }
};

Any and all information would be greatly appreciated! Thank you guys!!!

CloudScript
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
brendan avatar image
brendan answered

Well first, I need to point out that what you're trying to do won't work, as Cloud Script is designed for lightweight operations. Specifically, in the free (Essentials) tier, it's limited to 5 CPU seconds, and a max of 15 Server API calls (and depending on the calls, it's possible that 15 calls would exceed the CPU time, so you should always test boundary cases to confirm the timing on what you're trying to do).

But for cases where you do need to use player inventory in a Cloud Script, the issue above is that it's the Inventory element of the response that is the array.

When calls aren't working as expected when your in development, one handy technique is to simply log the response from the call, so that you can have a look at the specifics of what was returned.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.