Search Unity

Question Cloud Code update Inventory Item

Discussion in 'Cloud Code' started by VagelisGardikis, Feb 18, 2022.

  1. VagelisGardikis

    VagelisGardikis

    Joined:
    Apr 24, 2018
    Posts:
    20
    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:
    upload_2022-2-18_11-33-36.png
     
  2. Laurie-Unity

    Laurie-Unity

    Unity Technologies

    Joined:
    Mar 5, 2020
    Posts:
    220
    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.

    Code (JavaScript):
    1.  
    2.   // Add new random reward TICKET to player's inventory
    3.   const createdItem = await inventory.addInventoryItem(projectId, playerId,
    4.    { inventoryItemId:"TICKET",
    5.      instanceData: { "itemValue":itemValue,
    6.                      "itemExpiresAt":itemExpiresAt }
    7.    });
    8.   const playersInventoryItemId = createdItem.data.playersInventoryItemId;
    9.   logger.info("created Item : " + createdItem.data.playersInventoryItemId);
    10.  
    11.  
    12.   const updatedItem = await inventory.updateInventoryItem(projectId, playerId, playersInventoryItemId,
    13.     {
    14.        instanceData: {
    15.          "itemValue": 999
    16.      }
    17.    });
    18.  
    I hope that helps.
     
    Last edited: Feb 18, 2022
    VagelisGardikis likes this.
  3. VagelisGardikis

    VagelisGardikis

    Joined:
    Apr 24, 2018
    Posts:
    20
    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?
     
  4. Laurie-Unity

    Laurie-Unity

    Unity Technologies

    Joined:
    Mar 5, 2020
    Posts:
    220
    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.
     
    DavidZobrist likes this.