question

Laarni avatar image
Laarni asked

Hi. I am facing a little issue. I am trying to GetUserInventory but specifically the virtual currency. The API call works perfect but it returns me a value wrapped with parentheses. Something like ( 10).

1 comment
10 |1200

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

Laarni avatar image Laarni commented ·

Sorry. i forgot that Enter send the message. So my question is: How can i get only the Number instead of the parentheses and 5 spaces.

It goes straight on a UILabel. Iam on Xcode and obj C

0 Likes 0 ·

1 Answer

·
brendan avatar image
brendan answered

The virtual currency is returned in VirtualCurrency in the data of the response, as shown in the documentation: https://api.playfab.com/Documentation/Client/method/GetUserInventory. It's returned as a numeric value - no parentheses or spaces.

In our Objective C library, the virtual currency balances are returned in an NSDictionary in GetUserInventoryResult. Can you provide the code snippet showing how you're taking the value and adding it to the UILabel?

1 comment
10 |1200

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

Laarni avatar image Laarni commented ·

Thanks for the fast answer!! You put me on the right way. It s working fine now. I just fetched the value that was a number, turned it into a string value and Voila!

[[PlayFabClientAPI GetInstance]

     GetUserInventory:^(GetUserInventoryResult *result, NSObject *userData) {

               NSLog(@"Virtual currency:%@",result.VirtualCurrency.allValues);

         

            NSString *virtualCurrency = [result.VirtualCurrency.allValues objectAtIndex:0];

         

         _goldStars.text = [NSString stringWithFormat:@"%@",virtualCurrency];

         

         

     } failure:^(PlayFabError *error, NSObject *userData) {

         NSLog(@"error %@", error.errorMessage);

     } withUserData:nil];

    


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.