var SELL_PRICE_RATIO = 0.75; function SellItem_internal(soldItemInstanceId, requestedVcType) { var inventory = server.GetUserInventory({ PlayFabId: currentPlayerId }); var itemInstance = null; for (var i = 0; i < inventory.Inventory.length; i++) { if (inventory.Inventory[i].ItemInstanceId === soldItemInstanceId) itemInstance = inventory.Inventory[i]; } if (!itemInstance) throw "Item instance not found"; // Protection against client providing incorrect data var catalog = server.GetCatalogItems({ CatalogVersion: itemInstance.CatalogVersion }); var catalogItem = null; for (var c = 0; c < catalog.Catalog.length; c++) { if (itemInstance.ItemId === catalog.Catalog[c].ItemId) catalogItem = catalog.Catalog[c]; } if (!catalogItem) throw "Catalog Item not found"; // Title catalog consistency check (You should never remove a catalog/catalogItem if any player owns that item var buyPrice = 0; if (catalogItem.VirtualCurrencyPrices.hasOwnProperty(requestedVcType)) buyPrice = catalogItem.VirtualCurrencyPrices[requestedVcType]; if (buyPrice <= 0) throw "Cannot redeem this item for: " + requestedVcType; // The client requested a virtual currency which doesn't apply to this item // Once we get here all safety checks are passed - Perform the sell var sellPrice = Math.floor(buyPrice * SELL_PRICE_RATIO); server.AddUserVirtualCurrency({ PlayFabId: currentPlayerId, Amount: sellPrice, VirtualCurrency: requestedVcType }); server.RevokeInventoryItem({ PlayFabId: currentPlayerId, ItemInstanceId: soldItemInstanceId }); }
the functions are:
handlers.SellItem = function (args) { if (!args || !args.soldItemInstanceId || !args.requestedVcType) throw "Invalid input parameters, expected soldItemInstanceId and requestedVcType"; SellItem_internal(args.soldItemInstanceId, args.requestedVcType); };
basically just pasted the cloudscript from https://api.playfab.com/docs/tutorials/landing-players/inventory
I am trying to implement the sell item example where that iteminstanceid is from the getuserinventory and GO is the Gold
using postman :{ "FunctionName": "SellItem", "FunctionParameter" : { "soldItemInstanceId": "30AF2CA9937801B9" , "requestedVcType": "GO" } }
im getting a blanket javascriptexception:
{ "code": 200, "status": "OK", "data": { "FunctionName": "SellItem", "Revision": 17, "Logs": [], "ExecutionTimeSeconds": 0.1229812, "ProcessorTimeSeconds": 0, "MemoryConsumedBytes": 104344, "APIRequestsIssued": 2, "HttpRequestsIssued": 0, "Error": { "Error": "JavascriptException", "Message": "JavascriptException", "StackTrace": "" } } }
anyway i can get more of a detailed information to find out what the issue is - from what i gather the APIs are issued but doesnt get procecsed am i reading that apirequestsissued right? - i know it doesnt actually proccess because the VC doesnt increase for the player and the item doesn't get removed
thanks for the help!
Daniel