question

elblood21 avatar image
elblood21 asked

Get Virtual Currency in c#

hi , there're a way to get virtual currency in c# for unity? in the api i see examples ¿in json? but i dont understand how to do it ... there're no exists tutorial that explain how to get and set data! i just know how to get and set playerdata ( in c#) ... please help me

apisdata
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

I would recommend reading the tutorial on inventory, here: https://api.playfab.com/docs/tutorials/landing-players/inventory. It shows how to query the user inventory, including the virtual currency balances and recharge times, and provides examples in multiple languages, including Unity C#.

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

elblood21 avatar image elblood21 commented ·

hi , it dont shows how to get virtual currency ... i'm trying to get my gold(GD) and show it in ui text

0 Likes 0 ·
brendan avatar image brendan elblood21 commented ·

The GetUserInventory call mentioned in the tutorial returns both the player's VC balance and regeneration times.

0 Likes 0 ·
elblood21 avatar image elblood21 commented ·

voidGetInventory(){

PlayFabClientAPI.GetUserInventory(newGetUserInventoryRequest(),

LogSuccess, LogFailure);}

If i write that and logsuccess i dont get the virtual cureency balance

@brendan

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

Can you provide a title id and a user id? I'd like to attempt to reproduce the issue you're seeing.

0 Likes 0 ·
elblood21 avatar image elblood21 commented ·

How can i do that ? Do u have an example so i put my info in it?

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

I just meant posting them here on the forums so that I can attempt to see what you're seeing. If you would, please post the title id and the player id that you are using in your GetUserInventory call.

0 Likes 0 ·
elblood21 avatar image elblood21 commented ·

Idk what u mean

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

I wanted to know the title id of the title you're using for testing this and the player id of the player you're using. I was able to look up your title, though, and tried out a GetUserInventory request as user id 16A3705C700CFC21. I received this response:

{
    "code": 200,
    "status": "OK",
    "data": {
        "Inventory": [],
        "VirtualCurrency": {
            "DS": 100,
            "GL": 100000,
            "HM": 50,
            "SD": 50
        },
        "VirtualCurrencyRechargeTimes": {}
    }
}

That looks correct, so there must be something else wrong in your workflow.

0 Likes 0 ·
elblood21 avatar image elblood21 commented ·

Yeah that is thanks!! So how i get those in unity? In c# or something i dont understand

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

You can access that property of the response in Unity using something like this:

response.VirtualCurrency

There's an example of its use in Unity in our UnicornBattle demo game here: https://github.com/PlayFab/UnicornBattle/blob/master/UnicornBattle/Assets/Scripts/PF_StaticsAndHelpers/PF_PlayerData.cs#L78

The bit in particular that gets the virtual currencies is this:

foreach (var pair in result.VirtualCurrency)      
	virtualCurrency.Add(pair.Key, pair.Value);
0 Likes 0 ·
Show more comments

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.