Cloud Code update Inventory Item

Hello. I have on the cloud code a script for Adding an Inventory Item and a script for Deleteting one.
I cant make the Update Inventory Item though. I want to update an item's instance data but it is always empty. Can you help me?
Im trying something like this:
7906738--1007836--upload_2022-2-18_11-33-36.png

Hi Gardikis,

Thanks for sharing your code snippet. I think the issue is just due to the formatting of the parameters in your updateItem call.

Take a look at this example, the playersInventoryItemId is passed in as a string and the data object in the following optional inventoryRequestUpdate object

This example creates a reward ticket with random values, then updates one of the values.

  // Add new random reward TICKET to player's inventory
  const createdItem = await inventory.addInventoryItem(projectId, playerId,
   { inventoryItemId:"TICKET",
     instanceData: { "itemValue":itemValue,
                     "itemExpiresAt":itemExpiresAt }
   });
  const playersInventoryItemId = createdItem.data.playersInventoryItemId;
  logger.info("created Item : " + createdItem.data.playersInventoryItemId);
 
 
  const updatedItem = await inventory.updateInventoryItem(projectId, playerId, playersInventoryItemId,
    {
       instanceData: {
         "itemValue": 999
     }
   });

I hope that helps.

1 Like

Yes, it helped!! Thank you.
Can i ask when will Cloud Code support C#?
Or maybe when will a documentation about js for cloud code come out?

Hi Gardikis,

I'm glad to hear that example helped you.

I'm sorry I can't provide a timescale for C# support, but it is one of the things we are wortking on. We will be sure to post updates on the forum when we have more information that we can share.

There is documentation on Cloud Code and each ot the UGS Libraries, there are also lots of examples in the Usecase Samples Project . These should all be useful, but please let me know if you feel there is additional documentation that would make it easier.

1 Like