question

brendan-1 avatar image
brendan-1 asked

I created a cloudscript that calls server.GetPlayersInSegment. FunctionResult is a list of PlayerProfiles. Instead of returning PlayerProfile[] to the client, I just want to return a list of the PlayerIds contained within all of the PlayerProfiles.

(Unity) My application has a separate Admin functionality which will use the PlayerIds of all the players to Get and Update their PlayerData. The client executes a cloudscript that executes GetPlayersInSegment and returns the PlayerProfile[] as a FunctionResult. I do not want to make a class object for PlayerProfile all I want is a list of all the PlayerIds returned. I have spend way too much time looking for a way to solve this can someone please give me a pointer? I am having trouble with the FunctionResult JSON I believe and none of the PlayFab tutorials explain anything to do with working with FunctionResult.

unity3d
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

·
Made Wang avatar image
Made Wang answered

If you don't want to process JSON objects on the client side, then you can process the data in Cloud Script (Leagcy) and return it to the client side, refer to the code below. Note that doing this still requires some simple processing on the client side.

Also, we do not recommend calling GetPlayersInSegment in Cloud Script (Leagcy), because this API is resource intensive and should not be used in scenarios which might generate high request volumes. Using this API in Cloud Script (Leagcy) may result in timeout error.

handlers.GetPlayerIdInSegment=function(args,context){
    var result=server.GetPlayersInSegment({
        SegmentId: " "
    });
    var playerIds=new Array();
    result.PlayerProfiles.forEach(Item=>{
        playerIds.push(Item.PlayerId);
    })
    return playerIds;
}
10 |1200

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

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.