kantagara avatar image
kantagara asked

Get segments with cloud script

Hello everyone,

I want to list all of the users of my game so I could have an opportunity to have a one-on-one battle with someone I choose from that list.
Now, the idea I had in my mind to retrieve all of the users is to call (on the cloud) GetAllSegments() and then to get the first one (Because the first one contains all of the players), and then to retrieve that back to the client where the names would be displayed properly. Now the problem is I do not know how to get back all of the segments because when I write

//Cloud Code
handlers.hello = function (args, context) {
    return { messageValue: server.GetAllSegments() };

//Unity Code
ExecuteCloudScriptRequest request = new ExecuteCloudScriptRequest()
            FunctionName = "hello", // Arbitrary function name (must exist in your uploaded cloud.js file)
            FunctionParameter = new { inputValue = "YOUR NAME" }, // The parameter provided to your function
            GeneratePlayStreamEvent = true, // Optional - Shows this event in PlayStream
        PlayFabClientAPI.ExecuteCloudScript(request, OnCloudHelloWorld, OnErrorShared);

In the OnCloudHelloWorld function I get null for the messageValue value, so there must be a problem with that function. Can anyone help me with this? What am I doing wrong?

unity3dCloudScriptCustom Game Servers
10 |1200

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

1 Answer

brendan avatar image
brendan answered

Well first, the population of your game could be thousands or even millions of players, so trying to get a list of all of them from Cloud Script simply won't work - you would have to iterate on the query for the next block of players from the segment over and over, causing your script to timeout (or hit the API call limit).

It sounds like you're referring to an asynchronous game, in which case you could do matchmaking by getting the leaderboard of players with scores close to the local player (, and sending the "challenge" to that player. Alternately, you could use Photon Realtime, having players set up rooms with long TTLs, so that if a "player 2" hasn't joined by the time the first player is done, the session will stick around for another player to join.

Of course, if you mean a realtime game, we would recommend either using our matchmaker with custom game servers (hosted by us or not), or else using Photon Realtime.

10 |1200

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

kantagara avatar image kantagara commented ·

Thanks Brendan for the answer.

Okay so I have a better idea.. Can I somehow fetch my facebook friends who also have this game installed and then to ask them to beat my score?

0 Likes 0 ·
brendan avatar image brendan kantagara commented ·

Yes, you can query for friends via GetFriendsList, and you can include Facebook friends who are also playing the game in that list. Once you have that, you could request Push Notifications via a Cloud Script.

0 Likes 0 ·
kantagara avatar image kantagara brendan commented ·

Do I need to add those facebook friends in-game as well or they will be automaticly added to my friends list when they install the game?

0 Likes 0 ·
Show more comments

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.