question

My Studio avatar image
My Studio asked

problems with AddUserVirtualCurrencyRequest and GetUserInventoryRequest

Hi guys,

I am encountering a small problem,

When I use AddUserVirtualCurrencyRequest, the amount i fill in is 100, but playfab api ads the double.

This is my code:

		public void AddKr(int Punten)
		{
		AddUserVirtualCurrencyRequest request = new AddUserVirtualCurrencyRequest()
		{
			VirtualCurrency = "Kr",
			Amount = Punten
		};


			PlayFabClientAPI.AddUserVirtualCurrency (request, _Result, _Error);


		}

And this is what i see in dashboard of playfab.

My second problem is with updating the virtual currency amount of the player, after succesfully adding vc I update the field that holds the information.

		void _Result(ModifyUserVirtualCurrencyResult _thisResult)
		{
			ExecuteAfterTime (10);
		}


		IEnumerator ExecuteAfterTime(float time)
		{
			yield return new WaitForSeconds(time);
			GetKr();
		}


		public void GetKr()
		{
			GetUserInventoryRequest requestInv = new GetUserInventoryRequest()
			{


			};


			PlayFabClientAPI.GetUserInventory(requestInv, (resultInv) =>
			{
				foreach (var item in resultInv.VirtualCurrency)
			{
				Points.text = item.Value.ToString();
			}
			},
			(errorInv) =>
			{
				Points.text = errorInv.ErrorMessage;
			});


		}

The problem is, it doesn't update, am I doing something wrong?

BTW I develop in Unity.

With kind regards

capture.png (4.8 KiB)
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

For the first issue, there are two things tripping you up:

1. You're calling AddUserVirtualCurrency twice. I can see from the logs that in the case you described, we received two distinct requests to add the currency. Bear in mind that in the PlayStream debugger, if the same event occurs multiple times in a short period, the display will show them aggregated. If you click on the timestamp to view the full details, you'll see all the info on each event.

2. Because your currency is set up with a regeneration value, the first thing the service does is to recalculate the balance based upon the time that has passed since the last time it was incremented due to the regeneration rate. However, your regeneration rate is so low that this shows up as having added 0.

So the actual flow from reviewing the logs is:

  • Client calls AddUserVirtualCurrency to add 100 Kr
  • Regenerating currency is reclaculated - event generated, 0 Kr added
  • Requested amount is added to the currency - event generated, 100 Kr added
  • Client calls AddUserVirtualCurrency to add 100 Kr
  • Regenerating currency is reclaculated - event generated, 0 Kr added
  • Requested amount is added to the currency - event generated, 100 Kr added

For the second, can you try updating that to use a KeyValuePair for the VCs in the VirtualCurrency object? So this would be:

foreach( KeyValuePair<string, int> kvp in resultInv.VirtualCurrency)

With the value then being in kvp.Value.

2 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.

Joshua Strunk avatar image Joshua Strunk commented ·

I think you made a mistake on diagnosing the second issue. Var should be typing to exactly the same thing you wrote out. My best guess would be incorrect use of a function intended for use as a Unity Coroutine

void _Result(ModifyUserVirtualCurrencyResult _thisResult){

	ExecuteAfterTime(10);

}

IEnumerator ExecuteAfterTime(float time) {

	yield return new WaitForSeconds(time);

	GetKr();

}

Which needs to either be called with MonoBehaviour.StartCoroutine or in some other way managed.

0 Likes 0 ·
brendan avatar image brendan Joshua Strunk commented ·

Nice catch - serves me right for not writing a test to check the behavior. :)

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.