Alright, so I got the adding an item to inventory to work in cloud code, now I need to change the instance data. I’ve got this line of code:
const { InventoryApi } = require("@unity-services/economy-2.3");
module.exports = async ({ params, context, logger }) => {
const { itemId } = params;
const { projectId, playerId } = context;
const inventory = new InventoryApi(context);
const updateItem = await inventory.updateInventoryItem( projectId, playerId, itemId,
{
instanceData:
{
"stat1": 21,
"stat2": 13
}
});
}
which isn’t working. Its returning the error:
Invocation Error
------------------------------
RequiredError: Required parameter projectId was null or undefined when calling updateInventoryItem.
{
“message”: “Required parameter projectId was null or undefined when calling updateInventoryItem.”,
“name”: “RequiredError”,
“stackTrace”: [ ]
}
Which doesn’t make a lot of sense to me. Why would my code not have the projectId built in when I run it? I’m running it in the test ode on the UGS dashboard, which adds items to a player’s inventory, why am I geting this error when I try to update it?
EDIT: I finally got it working! Here is the code for anyone else that might need the help
const { InventoryApi } = require("@unity-services/economy-2.3");
module.exports = async ({ params, context, logger }) => {
const { projectId, playerId } = context;
const inventory = new InventoryApi(context);
const tsword = await inventory.getPlayerInventory({ projectId, playerId, inventoryItemIds: "TSWORD" });
const updated = await inventory.updateInventoryItem({
projectId,
playerId,
playersInventoryItemId: tsword.data.results[0].playersInventoryItemId,
inventoryRequestUpdate: {instanceData:
{
"stat1": 43,
"stat2": 43
}}});
}