I am trying to make a search engine of other players and receive the statistics and profile information But I keep getting null results in the cloud script. I'm using the DisplayName as a reference to find the player, also tried with playfabID but without success.
public class OtherPlayerData
{
public string playerId;
public string displayName;
public Dictionary<string, object> Profile;
public Dictionary<string, int> Statistics;
}
public void GetOtherPlayerDataByDisplayName(string displayName)
{
PlayFabClientAPI.ExecuteCloudScript(new ExecuteCloudScriptRequest()
{
FunctionName = "getOtherPlayerDataByDisplayName",
FunctionParameter = new { displayName },
GeneratePlayStreamEvent = true,
}, OnGetOtherPlayerDataSuccess, OnGetOtherPlayerDataError);
}
private void OnGetOtherPlayerDataSuccess(ExecuteCloudScriptResult result)
{
if (result.FunctionResult == null)
{
Debug.Log("Resultado vazio ou nulo");
return;
}
var data = JsonUtility.FromJson<OtherPlayerData>(result.FunctionResult.ToString());
Debug.Log("Nome do jogador desejado: " + data.displayName);
foreach (var stat in data.Statistics)
{
Debug.Log($"{stat.Key}: {stat.Value}");
}
}
private void OnGetOtherPlayerDataError(PlayFabError error)
{
Debug.LogError(error.GenerateErrorReport());
}
public void SearchOtherPlayerData()
{
string DisplayName = nameSerach;
GetOtherPlayerDataByDisplayName(DisplayName);
}
Acima é a função que estou utilizando no Client.
handlers.getOtherPlayerDataByDisplayName = function (args, context) {
var displayName = args.displayName;
var playerProfiles = server.GetPlayerProfiles({
Profiles: [{ DisplayName: displayName }],
ProfileConstraints: {
ShowDisplayName: true,
ShowStatistics: true,
}
});
if (!playerProfiles || playerProfiles.length === 0) {
return { error: "Jogador não encontrado" };
}
var playerProfile = playerProfiles[0];
return {
playerId: playerProfile.PlayerId,
displayName: playerProfile.DisplayName,
profile: playerProfile.Profile,
statistics: playerProfile.Statistics
};
};
This is the Revisions on the cloudScript I'm using to send the data. If someone could kindly give me a light.