Hey everyone!
I'm new to playfab and have been able to create a few cloudscripts with little difficulty. That is up until now! I'm having trouble creating a cloud script to implement the Revoke Inventory Items found here:
Originally I used the singular version, Revoke Inventory Item and got a functioning script. That said I dont think its the best way to revoke multiple items as I had it in a for loop and it will make multiple calls, where as the Revoke Inventory Items will only make one.
So far I tried a method like this (newCardsToDelete is an array of ItemInstanceIds transferred to the cloud script from the client):
var newCardsToDelete = args.newCardsToDelete; //Delete old Cards var deleteOldCards = server.RevokeInventoryItems( { PlayFabID: currentPlayerId, Items : newCardsToDelete });
When this didnt work I looked at the documentation again and noticed it doesnt need the PlayFabID field. So I removed that but it still didn't work. Then I noticed the Items field wants an array of player items rather than string InstanceIDs. So I went back and created some code where I got the players inventory checked if the item's ID matched an InstnaceID that the client sent. Once this was done that object was added to another array. However this still did not work.
var oldCardIds = args.oldCardIds; var getInventoryResult = server.GetUserInventory( { PlayFabID: currentPlayerId }); var inv = getInventoryResult.Inventory; const CardsToDelete = []; for(let i = 0; i < inv.length; i++) { if(oldCardIds.includes(inv[i].ItemInstanceId)) { CardsToDelete.push(inv[i]); } } //Delete old Cards var deleteOldCards = server.RevokeInventoryItems( { PlayFabID: currentPlayerId, Items : CardsToDelete });
I feel like I'm missing something obvious and have been stuck for a couple days now. Any help here would be much appreciated!
,Hey everyone,
So this is my first time using playfab and I'm having some difficulties creating a cloud script for Revoke Inventory Items. I've read through the documentation posted here https://learn.microsoft.com/en-us/rest/api/playfab/server/player-item-management/revoke-inventory-items?view=playfab-restand I'm still having some trouble. Originally, I was going to use the Revoke Inventory Item feature, and even got a cloud script to function the way I wanted. However I realized this wasn't an efficient way to do it since it was in a for loop and would create multiple calls rather than just one call by using Revoke Inventory Items. If anyone could help me out and give me a basic cloud script that will execute this I would appreciate it!
Thanks!