question

joeypc6 avatar image
joeypc6 asked

grant multiple itmes

I have This Code

  var CountItems = "";
  
  
      for (var i = 0; i < args.Count; i++) {


       
       if(i == 0){
            CountItems += args.itemType;
       }
       if(i > 0){
            CountItems += "," + args.itemType;
       }
    
       
     }
  log.debug(CountItems);
  
  if(FirstitemInstance != null){
    
    
    
       server.ConsumeItem({ PlayFabId: args.ID, ItemInstanceId: FirstitemInstance , ConsumeCount: args.Count });
  
       var result = server.GrantItemsToUser({
        // In your game, this should just be a constant
        CatalogVersion : "Items",
        PlayFabId : args.IslandID,
        ItemIds : [CountItems]
        });
  
    log.debug(result);
  }

This Gives me an error



but This Don't

umeCount: args.Count });
  
       var result = server.GrantItemsToUser({
        // In your game, this should just be a constant
        CatalogVersion : "Items",
        PlayFabId : args.IslandID,
        ItemIds : [8,8]
        });
  
    log.debug(result);
  }
apisCloudScript
10 |1200

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

brendan avatar image
brendan answered

Can you please provide the specific values you passed into the calls? It's not apparent from the above what the actual calls are you made. Also, can you provide the specific error response body you got back?

20 comments
10 |1200

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

joeypc6 avatar image joeypc6 commented ·

This is my code

i'm passing the item to the holder

handlers.DonateItem = function (args,IslandID,ID,itemType,Count){
 
   var inventory = server.GetUserInventory({ PlayFabId: args.ID});
   var FirstitemInstance = null;
  
    for (var i = 0; i < inventory.Inventory.length; i++) {
        if (inventory.Inventory[i].ItemId === args.itemType && inventory.Inventory[i].RemainingUses >= args.Count){
            FirstitemInstance = inventory.Inventory[i].ItemInstanceId;
        }
    }
  
  var CountItems = "";
  
  
      for (var i = 0; i < args.Count; i++) {
       
       if(i == 0){
            CountItems += args.itemType;
       }
       if(i > 0){
            CountItems += "," + args.itemType;
       }
    
       
     }
  log.debug(CountItems);
  
  if(FirstitemInstance != null){
    
    
    
       server.ConsumeItem({ PlayFabId: args.ID, ItemInstanceId: FirstitemInstance , ConsumeCount: args.Count });
  
       var result = server.GrantItemsToUser({
        // In your game, this should just be a constant
        CatalogVersion : "Items",
        PlayFabId : args.IslandID,
        ItemIds : [CountItems]
        });
  
    log.debug(result);
  }
}

0 Likes 0 ·
Andy avatar image Andy ♦♦ joeypc6 commented ·

Is there an error somewhere? Looking at the response you got below, everything seams fine.

0 Likes 0 ·
joeypc6 avatar image joeypc6 Andy ♦♦ commented ·

the player didn't revised any item

0 Likes 0 ·
Show more comments
joeypc6 avatar image joeypc6 commented ·

So I Made A Script That makes Only 1 Player Donates And Add +1 To The Inventory instance
, New Joined Players Loads The Hole inv So i think that makes my script unique and work

0 Likes 0 ·
joeypc6 avatar image joeypc6 joeypc6 commented ·
0 Likes 0 ·
brendan avatar image brendan joeypc6 commented ·

I'm not clear on what exactly you mean by "Donates and Add +1", but to be clear:

You cannot use player inventory as a collection point for any non-trivial number of players. This is guaranteed to fail at scale, and could get your title blocked from the service due to abusive behavior. If your design calls for that, can you please describe from a design level - meaning the actual gameplay experience you want to provide players - so that we can help guide you to a solution that will work.

0 Likes 0 ·
joeypc6 avatar image joeypc6 brendan commented ·

"Donates and Add +1"

i meant That I Add 1 To The Inventories that the players have in game (client side only)


"an you please describe from a design level"

I want To make an island based game that 4-6 players build people focus on 3 materials To Use In Their Crafting/Building i won't update the island inventory that frequent something like every 3 - 5 mins


this is my dream concept so don't tell me that i doesn't work pls :(

0 Likes 0 ·
Show more comments
joeypc6 avatar image
joeypc6 answered

And This is The result

{
    "EventName": "player_executed_cloudscript",
    "Source": "CloudScript",
    "FunctionName": "DonateItem",
    "CloudScriptExecutionResult": {
        "FunctionName": "DonateItem",
        "Revision": 182,
        "FunctionResult": null,
        "FunctionResultTooLarge": null,
        "Logs": [
            {
                "Level": "Debug",
                "Message": "8,8",
                "Data": null
            },
            {
                "Level": "Debug",
                "Message": "{\"ItemGrantResults\":[{\"PlayFabId\":\"37BF6A131AD467EC\",\"Result\":false,\"ItemId\":\"8,8\",\"UnitPrice\":0}]}",
                "Data": null
            }
        ],
        "LogsTooLarge": null,
        "ExecutionTimeSeconds": 0.1942093,
        "ProcessorTimeSeconds": 0,
        "MemoryConsumedBytes": 61968,
        "APIRequestsIssued": 3,
        "HttpRequestsIssued": 0,
        "Error": null
    },
    "EventNamespace": "com.playfab",
    "EntityType": "player",
    "TitleId": "59A9",
    "EntityId": "2CF97F2C60F282AF",
    "EventId": "61848289d960408a82561e6d57a54f56",
    "SourceType": "BackEnd",
    "Timestamp": "2018-08-31T09:50:44.0212826Z",
    "History": null,
    "CustomTags": null,
    "Reserved": null,
    "PlayFabEnvironment": {
        "Vertical": "master",
        "Cloud": "main",
        "Application": "logicserver",
        "Commit": "896e065"
    }
}
10 |1200

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

joeypc6 avatar image
joeypc6 answered

The Ultimate Fix

  for (var i = 0; i < args.Count; i++) {
       var result = server.GrantItemsToUser({
        // In your game, this should just be a constant
        CatalogVersion : "Items",
        PlayFabId : args.IslandID,
        ItemIds : args.itemType
        });
        }
I mean It Works That's All
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.