Sign In Register

How can we help you today?

Start a new topic
Answered

Account Details Request

Good Morning,


When my main scene in my game opens up i immediately load all the account details of the current player that is logged in via GameSparks. I have the attached code that is bellow. I have it working with currency but now i am trying to get the quantity and name of my virtual goods so i can assign them to some text i have in my scene. How would i pull this data and assign them to local variables?




new AccountDetailsRequest ()

   .Send ((response) => {

    IList<string> achievements = response.Achievements;

    long? currency1 = response.Currency1;

    long? currency2 = response.Currency2;

    GSEnumerable<GameSparks.Api.Responses.ListVirtualGoodsResponse._VirtualGood> vgsList = response.VirtualGoods;

 

    foreach(GameSparks.Api.Responses.ListVirtualGoodsResponse._VirtualGood vg in vgsList)

    {

     

     string shortCode = vg.ShortCode;

     Debug.Log(shortCode);

 

    }

 

 

 

    string goldCoins;

    string greenCrystals;

 

    goldCoins = currency1.ToString();

    greenCrystals = currency2.ToString();

 

    GameObject.FindGameObjectWithTag("Gold Number").GetComponent<TextMeshProUGUI>().text = goldCoins;

    GameObject.FindGameObjectWithTag("Green Crystal Number").GetComponent<TextMeshProUGUI>().text = greenCrystals;

    GameObject.FindGameObjectWithTag("Display Name").GetComponent<TextMeshProUGUI>().text = response.DisplayName;

 

 

    Debug.Log("Achievements: " + achievements);

    Debug.Log("Gold Coins: " + goldCoins);

    Debug.Log("Green Crystals: " + greenCrystals);

    ;

 

  });



Best Answer

You could try something like this...

 new GameSparks.Api.Requests.AccountDetailsRequest().Send((resp)=>{

 Dictionary<string, int> vgList = new Dictionary<string, int>();

 foreach(string vgShortCode in resp.VirtualGoods.BaseData.Keys)
 {
 Debug.Log(vgShortCode);
 Debug.Log(resp.VirtualGoods.GetInt(vgShortCode).Value);
 vgList.Add(vgShortCode, resp.VirtualGoods.GetInt(vgShortCode).Value);
 } 

 });

1 Comment

Answer

You could try something like this...

 new GameSparks.Api.Requests.AccountDetailsRequest().Send((resp)=>{

 Dictionary<string, int> vgList = new Dictionary<string, int>();

 foreach(string vgShortCode in resp.VirtualGoods.BaseData.Keys)
 {
 Debug.Log(vgShortCode);
 Debug.Log(resp.VirtualGoods.GetInt(vgShortCode).Value);
 vgList.Add(vgShortCode, resp.VirtualGoods.GetInt(vgShortCode).Value);
 } 

 });

Login to post a comment