question

simong@everguild.com avatar image
simong@everguild.com asked

Is there a way to get access to a CatalogItem with its ItemId?

Simple question, so far I can only retrieve a list of all the catalog items. Or I don't want to iterate over all my catalog just to find one item.... Haven't found any way to do that so far.

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

That's because the same ItemId could be in all your catalogs - in fact, that's really the design. The way catalogs are normally used is that all items for the game are in the catalog, with the version ID used to make sure the current version of the game is pulling down the right one. That way, for updated versions of your game, you can expand upon the catalog by creating a new version ID, which the new game version will reference.

For situations where you want to have sub-divisions of the catalog, I would recommend using Stores, as that's a convenient way to make sub-groupings of catalog items.

4 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.

simong@everguild.com avatar image simong@everguild.com commented ·

The problem is I need to get access to the custom data of these items from a cloud script. I don't need the store item itself.
if I grant 10 items to the user's inventory that means for each of them I have to iterate all over the catalog to find its corresponding ItemId in the catalog so I have access to the custom data. Aren't there any more elegant/optimized approach?

0 Likes 0 ·
brendan avatar image brendan simong@everguild.com commented ·

What's the actual gameplay experience you're attempting to enable? If we can take a step back and look at the problem from a higher level, we may be able to recommend a solution which suits your needs more cleanly. What's the feature in question?

0 Likes 0 ·
Martin L avatar image Martin L simong@everguild.com commented ·

I'd like this functionality for a similar reason. I am having to iterate over a complete catalog multiple times when granting a bundle or opening a container in order to access the item Tags because I only have the ItemId, InstanceId or Class, and I want to use those tags to drive the creation of custom data.

0 Likes 0 ·
Joshua Strunk avatar image Joshua Strunk Martin L commented ·

Just iterate through your catalog once and build a lookup table that uses the ItemIds for the keys.

0 Likes 0 ·
simong@everguild.com avatar image
simong@everguild.com answered

Let say the player wants to sell an item to get gold. The price is based on the rarity of the item. So I want to send a request to my cloud script with the item id he wants to sell, make sure he has it in its inventory and lookup in the custom data the rarity of the object so I can make sure I give the right amount of gold to the player. If when granting an item to the user's inventory the custom data of the catalog item were copied that would be great but so far it's not and I have to manually add the custom data to the ItemInstance which is not efficient at all. If I grant 100 items through a bundle, for each of them I would still have to search for the catalog item and copy the custom data. In this case, the rarity of the object

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

To do this specifically (getting rarity info on the item, assuming that the rarity is meant to be global to all items of each type), you would indeed need to grab the player's inventory and the game's catalog in the Cloud Script call, in order to find the item in each.

The reason the catalog data is not copied into the item instance is because the catalog-level custom data is global data - changing it should apply to all item instances on all players. Custom data that is on the item instance is specific to that item (and potentially overrides the global data, depending on your implementation).

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.

simong@everguild.com avatar image simong@everguild.com commented ·

Yep I totally understand, that why I was thinking being able to have access to one or more catalog items by specifying an array of ids would be so useful...

0 Likes 0 ·
brendan avatar image
brendan answered

I'm hearing two different things in this thread.

1. The ability to have CustomData propagate to item instances (and so, no longer be global values, but rather local to the instance). Two possible approaches to this: CustomData as a parameter to calls (https://community.playfab.com/content/idea/895/210537287-Atomically-Creating-Items.html), and being able to tag catalog item CustomData as "copy to instances" (https://community.playfab.com/content/idea/665/208409457--renamed-Copy-Catalog-item-properties-to-instances.html).

2. The ability to get the global custom data for an ItemId from the catalog, so that you can use it as input to logic for an action being taken on an item instance. It's this latter use for which I would recommend getting the catalog locally and caching it, even if its for use in Cloud Script, as it will be more efficient for any case where you're processing more than one item.

2 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.

Martin L avatar image Martin L commented ·

Yes, I have use case number 2 above. Where is "local" to cache the catalog when it is to be used by CloudScript please?

0 Likes 0 ·
brendan avatar image brendan Martin L commented ·

You can do this by defining a static object to hold the catalog in Cloud Script. Check it when the script runs to see if it has the current catalog value and load it if it does not. Note that this does mean that if you make changes to the catalog, they won't be picked up right away, so you may want to use the catalog version system when you update to change catalog info (store the current catalog version in Title Data, and use that to determine which catalog to load).

0 Likes 0 ·

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.