Sign In Register

How can we help you today?

Start a new topic
Answered

Following "Social Friends System" in Tips and Tricks forum

Hi, i have an little issue here :D
I followed the tutorial and everything is working fine in the test harness. So the next step for me would be to put all this into unity and there is the issue... I have it so far when i press my "Find Player" button, i get the playerId and playerName in the response of my LogEventRequest().

  

GS: RECV:{"@class":".LogEventResponse","requestId":"636042889074145984_3","scriptData":{"player":[{"playerId":"5789e3b91474e7048f910557","playerName":"Gozzy"}]}} 

 now call this method:
   

public void FindPlayer()
        {
            new GameSparks.Api.Requests.LogEventRequest()
                .SetEventKey("findPlayer")
                .SetEventAttribute("displayName", "Gozzy")
                .SetEventAttribute("entryCount", "10")
                .SetEventAttribute("offset", "0")
                .Send((response) => {
                    if (!response.HasErrors)
                    {
                        Debug.Log("Finding Player...");
                        //GSData data = response.ScriptData.GetGSData("player");
                        string playerId = response.ScriptData.GetString("playerId");
                        string playerName = response.ScriptData.GetString("playerName");
                        Debug.Log("ID: " + playerId + " Name : " + playerName);
                    }
                    else
                {
                    Debug.Log("Error finding player....");
                }
            });
        }

The playerId and playerName variables are empty in "Debug.Log("ID: " + playerId + " Name : " + playerName);"
Any suggestion what i have to do to get this to work? What i am doing wrong? Need more info what i am doing?


Best Answer

Don't worry, finally i found out how to do it

  

GSData gsData = response.ScriptData;
List<GSData> players = gsData.GetGSDataList("player");
foreach(GSData player in players)
{
    string gsPlayerId = player.GetString("playerId");
    string gsPlayerName = player.GetString("playerName");
    Debug.Log("ID: " + gsPlayerId + " Name : " + gsPlayerName);
}

  


How do i Access this to get the playerId and playerName out of it??

 

{
 "@class": ".LogEventResponse",
 "scriptData": {
  "player": [         //<<-- How to access this??
   {
    "playerId": "54edc940e4b08771a2ed730a",
    "playerName": "Shane"
   }
  ]
 }
}

 I tried so many things but i cant find the way to access this...

Answer

Don't worry, finally i found out how to do it

  

GSData gsData = response.ScriptData;
List<GSData> players = gsData.GetGSDataList("player");
foreach(GSData player in players)
{
    string gsPlayerId = player.GetString("playerId");
    string gsPlayerName = player.GetString("playerName");
    Debug.Log("ID: " + gsPlayerId + " Name : " + gsPlayerName);
}

  

Hi David,


Let us know if you need any further assistance with this.


Thanks,

Liam

Login to post a comment