question

duartedd avatar image
duartedd asked

Playfab sellItem example

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

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
brendan avatar image
brendan answered

The sample only shows minimal error checking, and doesn't show using catch() to collect the error text and return it. Have a look at this thread for more info on try/throw/catch and using it for debugging Cloud Script: https://community.playfab.com/questions/7595/cloudscript-how-do-i-properly-return-an-error-to-t.html. Once you have the error message, you should have the info you need. If not though, can you let us know the Title ID, Cloud Script revision, and PlayFab ID of the test user?

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.