Search Unity

Bug Can't configure new items? Old items not updating?

Discussion in 'Economy' started by Corva-Nocta, Feb 13, 2023.

  1. Corva-Nocta

    Corva-Nocta

    Joined:
    Feb 7, 2013
    Posts:
    801
    Hey all, trying to figure out the mystery that is Cloud Code and currently working on just adding items to the inventory but I am having some weird errors. I made a few test items that are working fine but I am having two odd issues:

    1.) I created a few new test items but they don't work in the code. I can add the old items to a players inventory, but I can't add the new items I created. I have created the items and hit the Publish button several times, the items show up in my list of items, but when I try to run the cloud code it says that it can't find the item. I know the item ID is correct (Its just TSWORD, kinda hard to mess up) and I know it is the ID and not just typing in the name. But for some reason it keeps treating it like this item doesn't exist, despite having created it and it showing up in the list of items. And yes, I have created this item and hit Publish multiple times.

    2.) I added some custom stats to an old item. It was previously blank, now I just added two new custom parameters in the JSON code. When I check older players' inventories that have that item, the stats don't show up on the item. Even when I add that item to a new player's inventory, the stats never show up when I check the inventory. Its like the stats are never there? But they are, I can see them plainly when I go to edit the item. And I've hit the Publish button like 5 times now. What else can I possibly be missing?
     
  2. Laurie-Unity

    Laurie-Unity

    Unity Technologies

    Joined:
    Mar 5, 2020
    Posts:
    220
    Hi @Corva-Nocta

    I think the answers to both these questions may have been answered already in some of your other posts, but for anybody stumbling accross this one.

    1) The first thing to check is that you have Published the item, you state that you have so the next thing to check would be your Cloud Code script, to ensure that you are calling the Economy methods with the item ID correctly defined in the request. Please take a look at this documentation on GetPlayerInvetory request

    I would expect your code to look something like
    Code (CSharp):
    1. const swords = await inventoryApi.getPlayerInventory({projectId, playerId, inventoryItemIds : ["TSWORD"]});
    2)
    CustomData
    is applied to an item definition. When a player receives an Insatnce of an object it contains an empty
    InstanceData
    object. It is on you to copy the custom data or any additional new data parameters on to the Instance as you create it.

    Take a look at the Custom Data documentation and the code snippets in my reply to your other post.

    I hope that helps.
     
  3. Corva-Nocta

    Corva-Nocta

    Joined:
    Feb 7, 2013
    Posts:
    801
    Ah ok I think that does help. So when I create a new item with instance data (in the configuration screen) its more like saying "Here is an item, this is the information that it can have, but right now has none", if that is the case then what is the point of setting the values in the instance data when you make the item? If I make a brand new item of Sword and give it an instance data of "attack": 5 then what is the point of setting the 5 if I have to manually set it when I add the item to an inventory?
     
    Last edited: Feb 14, 2023
  4. Laurie-Unity

    Laurie-Unity

    Unity Technologies

    Joined:
    Mar 5, 2020
    Posts:
    220
    Yes, that's right, but I would reword your statement a bit.

    "When I create a new item definition in the dashboard I can apply Custom Data to it"
    "When a player receives an instance of an item it will not have any Custom Data but you can populate its instance data with values from the item definition's Custom Data along with any other parameter values that you might want to access of modify at an individual item instance level.


    To answer the second part of your question. The point is that you have a baseline starting point that all swords can inherit e.g. attack 5 in your example. And if I decide 5 isn't high enough I can chage it my item definition which my game an use on all new swords after that. But at an instance level, if a player receives an instance of a sword then proceeds to try an mine copper ore with it, you can blunten it and reduce that instance of the swords data to attack 2 or less.

    The custom data on an item definition is similair to remote config, in that you would use it as a configuration starting point. But the instance data is something you can modify dynamicaly for each individual instance of an item in the game.
     
  5. doublehitgames

    doublehitgames

    Joined:
    Mar 5, 2016
    Posts:
    97
    I only just arrived here.
    Currently (economy 2.4), is there any way to acquire an item through a purchase and the customized data already comes as a default instance?

    Currently, when we store an item that has customized data in the store, it goes to the player's inventory as NULL. The correct option would be to go with the customized data instantiated with the values already defined as default.

    If you don't have it, please. Include the option for the user to inform whether or not the inventory item needs custom data to be instantiated as DEFAULT.