I have spent hours trying to get data from my players inventory but i cant seen to figure out how to get it to work right. all it does is say undefined
function inv() { // save these values locally to ease use // save title id // build http request object for LoginWithCustomId var GetUserInventoryRequest = {}; OutputStatus("Logging in..."); PlayFabClientSDK.GetUserInventory(GetUserInventoryRequest, (response, error) => { if(error) { OutputError(error); } else { // display account details var result = response.data; var inv = result.Inventory var status = inv.ItemId; OutputStatus(status); } }); };
Answer by Made Wang · Nov 02, 2021 at 03:06 AM
The callback value Inventory of the GetUserInventory method is an array, even if there is only one data inside. I modified your code, you can use the following code and refer to the api document for testing.
function inv() { // save these values locally to ease use // save title id // build http request object for LoginWithCustomId var GetUserInventoryRequest = {}; OutputStatus("Logging in..."); PlayFabClientSDK.GetUserInventory(GetUserInventoryRequest, (response, error) => { if(error) { OutputError(error); } else { // display account details //var result = response.data; //var inv = result.Inventory; //var status = inv.ItemId; //OutputStatus(status); var result = response.data; var inv = result.Inventory; for(var i=0;i<inv.length;i++) { var status=inv[i].ItemId; OutputStatus(status); } } }); }