Sign In Register

How can we help you today?

Start a new topic

Calling findPlayers in Unity - Not receiving game data

I'm following the tutorial found here: https://docs.gamesparks.com/tutorials/social-features/creating-custom-friends-lists.html


I'm now trying to access the game data (friends list) in Unity.


I'm making the following event request in Unity:


        new GameSparks.Api.Requests.LogEventRequest()
            .SetEventKey("findPlayers")
            .SetEventAttribute("displayName", playerName)
            .Send((response) =>
            {
                if (!response.HasErrors)
                {
                    GSData data = response.ScriptData;
                    var playerList = data.GetGSDataList("playerList");

                    foreach (var player in playerList)
                    {
                        string playerReceived = player.GetString("displayName");

                        Debug.Log("Player Found: " + playerReceived);

                        foundPlayerText.text = playerReceived;
                    }
                }
                else
                {
                    Debug.Log("Error Finding Player...");
                }
            });
    }

 


The issue is that the playerList doesn't get populated. This is what the playerList looks like in the console:

System.Collections.Generic.List`1[GameSparks.Core.GSData]

Everything works well in the test harness:

image


And this user definitely exists in the Game Data:


However, when I check the log entry for the calls being made from Unity, the response is empty!


So I imagine my api request is not setup correctly?

Any input would be much appreciated!


Didn't include my other images:

image

Hello Rudy,


can you you put your cloud code please ?


Rgrds


Diego

Hi barudy,


Apologies for the late reply. Since I'm following one of GameSparks tutorials, my cloud code is identical:

//Get Game Service Data API
var API = Spark.getGameDataService();
//Forward declare condition
var condition;
//Forward declare player list which we will populate with entries based on our query
var playerList = [];

//Check for input and change query based on input
if(Spark.getData().userName != "null")
{
    var userNameCondition = API.S("userName").eq(Spark.getData().userName);
    condition = addCondition(condition, userNameCondition);
}

if(Spark.getData().displayName != "null")
{
    var displayNameCondition = API.S("displayName").eq(Spark.getData().displayName);
    condition = addCondition(condition, displayNameCondition);
}

if(Spark.getData().country != "null")
{
    var countryCondition = API.S("country").eq(Spark.getData().country);
    condition = addCondition(condition, countryCondition);
}

if(Spark.getData().city != "null")
{
    var cityCondition = API.S("city").eq(Spark.getData().city);
    condition = addCondition(condition, cityCondition);
}

//Exclude this player (yourself)
condition.and(API.S("userName").ne(Spark.getPlayer().getUserName()));

//Run query
var entryList = API.queryItems("playerList", condition);

//If query has errors
if(entryList.error()){
     Spark.setScriptError("ERROR", entryList.error());
     Spark.exit();    
}
else
{
    //If no errors and entries
    var temp;
    var OBJ;
    //Loop through entries
    // TODO: Limit entries given a threshold (you don't want to list everyone in Canada!)
    while (entryList.cursor().hasNext())
    {
        //Get reference of entry
        temp = entryList.cursor().next();
        //Populate data and ID of entry
        OBJ = temp.getData();
        OBJ.Id = temp.getId()
        //Add to list of players array
        playerList.push(OBJ);     
    }
    //Return list
    Spark.setScriptData("playerList", playerList)
}

//Function to dynamically create a compound query
function addCondition(condition, otherCondition) {
    if (condition)
    {
        return condition.and(otherCondition);
    }
    return otherCondition;
}

 
Hope this helps!

Login to post a comment