question

Ozan Yilmaz avatar image
Ozan Yilmaz asked

Is the result of GrantItemsToUser sorted?

Hello everyone,

Does GrantItemsToUser API always return the list of item instances in the order of the data I send? For example, the code down below:

    var grantItems = {
        "PlayFabId": currentPlayerId,
        "CatalogVersion": "Items",
        "ItemIds": ["Item1", "Item2", "Item3"]
    };

    var grantItemsResult = server.GrantItemsToUser(grantItems);

    grantItemsResult.ItemGrantResults[0] // is this Item1's data always?
    grantItemsResult.ItemGrantResults[1] // is this Item2's data always?
    grantItemsResult.ItemGrantResults[2] // is this Item3's data always?

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

·
Rick Chen avatar image
Rick Chen answered

Yes. The order should be the same. However, this is not a good practice to write the code, as our PlayFab system constantly updates, we could not promise that the order will always be the same. A good practice would be to find the items by id. For example:

  for(var i=0;
i<grantItemsResult.ItemGrantResults.length;i++){
                
if(grantItemsResult.ItemGrantResults[i].ItemId == "Item1"){
// your logic
}
if(grantItemsResult.ItemGrantResults[i].ItemId == "Item2"){
// your logic
}
if(grantItemsResult.ItemGrantResults[i].ItemId == "Item3"){
// your logic
}
}
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.