question

michaelbb avatar image
michaelbb asked

Don't receive UserInventory

Hi there,

I am seeking to get my inventory, especially my virtual currency for my players, I am struggling to find the error or the right solution.

Each time, I run my app it does not give me the right result.

I am working on a UWP for Windows 10.

In my mainpage I call the method UpdateCurrency to display the values for each currency without any success.

public static int Coins { get { return _coins; } }
private static int _coins; public static int Lives { get { return _lives; } }
private static int _lives;
public async static void UpdateCurrency()
{ var coins = await PlayFabClientAPI.GetUserInventoryAsync(new GetUserInventoryRequest);


if (coins.Result.VirtualCurrency.ContainsKey("CO"))
{
_coins = coins.Result.VirtualCurrency["CO"];
} if (coins.Result.VirtualCurrency.ContainsKey("LV"))
{
_lives = coins.Result.VirtualCurrency["LV"];
} }

Hopefully you could help me with that.

Many thanks in advance,

Best wishes,

Michael

In-Game Economywindows
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

·
JayZuo avatar image
JayZuo answered

Did you get any error while using this code? The only issue I can find in your posted code is that you are missing "()" after "new GetUserInventoryRequest". It should be

var coins = await PlayFabClientAPI.GetUserInventoryAsync(new GetUserInventoryRequest());

After this, I can get user's virtual currency correctly. If you still have this issue, please check in Game Manager to make sure the player does have virtual currencies named "CO" and "LV".

8 comments
10 |1200

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

michaelbb avatar image michaelbb commented ·

Hi and thanks for your quick reply.

I don't get any error messages back.

i also have the correct names for the virtual currency.

in my game center I see that the player has LV=5 and CO = 200.

What I noticed is that the if-statements are not executed.

After "new GetUserInventoryRequest" it returns var coins = 0.

0 Likes 0 ·
Andy avatar image Andy ♦♦ michaelbb commented ·

I do not understand how var coins = 0. coins should be of type PlayFab.PlayFabResult<PlayFab.ClientModels.GetUserInventoryResult>. I could see it being null somehow, but not 0.

Could you share the title id and player id that you're working on. I'd like to take a look at the configuration.

0 Likes 0 ·
michaelbb avatar image michaelbb commented ·

Hi Andy,

sure. The play id is:

E1C24F9E75861970

And title id: 9C02

Many thanks in advance

Best wishes,

Michael

0 Likes 0 ·
Andy avatar image Andy ♦♦ michaelbb commented ·

Alright, I'm stumped. When I run the exact code you posted (with the one syntactical fix) using the exact player you used, I get the expected results (_coins = 200, _lives = 5). There must be something else going on. You're either not access the player you think you are or the code you posted is not exactly what's being run.

Is it possible for you to attach a fiddler trace? I'd like to inspect the network traffic to ensure everything aligns with what I see.

0 Likes 0 ·
michaelbb avatar image michaelbb commented ·

Sure can send you further infos.

I also access the correct player and see its VC in the game manager.

I can send you further infos but not sure which infos you're looking for (fiddler trace?)

0 Likes 0 ·
michaelbb avatar image michaelbb commented ·

What's also a bit curious is that, I checked it a couple of times and sometimes I receive the infos from VC and sometimes not, without changing anything

0 Likes 0 ·
Andy avatar image Andy ♦♦ michaelbb commented ·

That behavior (inconsistent results) indicates something to do with timing. Fiddler is a tool for capturing http traffic. It can be useful for cases like this where you want visibility into what's actually happening over the network.

0 Likes 0 ·
michaelbb avatar image michaelbb commented ·

Have to search for this kind of tool as I never used it before

0 Likes 0 ·

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.