Sign In Register

How can we help you today?

Start a new topic

cloud code: ListGameFriendsRequest -> send returns undefined from time to time


I'm trying to get friends list with some custom data. So instead of calling ListGameFriendsRequest directly from unity, I created a custom event and I'm calling SparkRequests.ListGameFriendsRequest() and adding the custom data myself.

From time to time I'm receiving this error:

TypeError: Cannot read property "length" from undefined (event/GET_FRIENDS.js#14)

So sometimes it works, sometimes it doesn't

Here is the cloud code:  (the problem is response.friends;  returns undefined)

The problem resolves once I logout and relogin but its not something I can ask from the players to keep doing it.

var friendsRequest = new SparkRequests.ListGameFriendsRequest();
var response = friendsRequest.Send();
var friends = response.friends; 

for (var i = 0; i < friends.length; i++){
    var playerData = Spark.runtimeCollection("playerData"); // get the collection data
    var currentPlayer = playerData.findOne({
        "playerID": friends[i].id
    }); // search the collection data for the entry with the same id as the player

    friends[i].completedCategoryCount = currentPlayer.completedCategoryCount;
    friends[i].currentRound = currentPlayer.playerRound;
    friends[i].fbID = (friends[i].externalIds).FB;

Spark.setScriptData("friends", friends);

  This is the first time I'm integrating gamesparks to my game.

Am I doing something wrong? or missing something?

May it happens due to connecting from multiple devices? but even if so, its not happening all the time but just from time to time.

note: gamesparks is on preview mode


2 people have this question

Hi Cem,

What is the name of your game ? Can you let me know the playerId of the player who is seeing this behavior please ? I'll take a closer look for you.



fyi these are the check results when the problem occurs.

GS.Authenticated == true
GS.GSPlatform.AuthToken != string.Empty
FB.IsInitialized == true
FB.IsLoggedIn == false

(although I was authenticated by facebook)

also tried new GameSparks.Api.Requests.ListGameFriendsRequest() 

it returned without errors, but seems empty

Hey, so was this ever resolved/identified what the issue was? I am experiencing same behavior - it just started to happen really, had 0 problems a month ago. I've also tried with different syntax approach -> same result.

(our game is also in preview mode)

Login to post a comment