question

racso avatar image
racso asked

Get the amount of items in a bundle

Context: I'm using Unity SDK. I'm using GetCatalogItems to get the items in a catalog. With it, I can obtain a list of CatalogItem objects.

Some of those objects are bundles. CatalogItem.Bundle.BundledItems returns the list of items bundled in that bundle. However, I can't find how to know the amount of each item contained in the bundle (e.g.: this bundle contains 3 card_1).

How can I get the amount of each item contained in a bundle?

apissdks
10 |1200

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

Marcus Nixon avatar image
Marcus Nixon answered

Hi Racso,

To add on to what SethDu stated, when you make your call to GetCatalogItems, does your bundle not return with multiple instances of your items like in the example below?

"Bundle": {
	"BundledItems": [
		"Common Accessory",
		"Common Accessory",
		"Common Accessory",
		"Common Accessory",
		"Uncommon Accessory",
		"Uncommon Accessory",
		"Uncommon Accessory",
		"Uncommon Accessory",
		"Uncommon Accessory"
	],
	"BundledResultTables": []
}

1 comment
10 |1200

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

racso avatar image racso commented ·

Thanks for the comment, Marcus. This is the correct answer. Indeed, if you receive more than 1 unit of an item, the id of that item is included multiple times in the BundledItems list, even if they're stackable.

It's a bit weird, as that means that a bundle with 100 Potions will contain a list with 100 "Potion" ids, but I guess it does the job.

Thanks for the help.

0 Likes 0 ·
Seth Du avatar image
Seth Du answered

In the normal circumstance, the Catalog in a game will not change frequently (only when the game’s updates), which means you should maintain a local database in the client and no matter in what form such data is stored, it can be used as reference for later item management.

What I am trying to say is even though you are able to iteratively call API to traversal the containers to get all items, we suggest not doing it. Too many calls no only have bad gameplay experience, but also have possibility exceeding the limits. That’s why you need to do it locally in your client.

1 comment
10 |1200

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

racso avatar image racso commented ·

Thanks for the answer, but I don't understand how is it related to my question.

My question is: How can I know how many units of each item are contained in a bundle?

For example: A Bundle contains 3 swords, 5 shields and 10 potions. If I request the catalog and check the corresponding CatalogItem.Bundle.BundledItems, I get this list: { "sword", "shield", "potion"}. It doesn't include the amount of each item. How can I know that number?

0 Likes 0 ·
jrDev avatar image
jrDev answered

Hello,

Currently looking for an answer to getting the "quantity" of the item in the bundle contents. Where is this stored?

Thanks,

jrDev

10 |1200

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

jrDev avatar image
jrDev answered

Hello,

Here is the actual code that can be used to do this:

//Loop and calculate Quantity manually because PlayFab doesn't give the quantity in the API
for(int n = 0; n < result.Catalog[0].Bundle.BundledItems.Count; n++){
								
	//Reference the name
	itemName = result.Catalog[0].Bundle.BundledItems[n];
									
	//Get quantity by finding all similar names
	quantity = result.Catalog[0].Bundle.BundledItems.Where(d => d == itemName).ToList().Count;
			
}

Thanks,

jrDev

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.