Sign In Register

How can we help you today?

Start a new topic

How to update a response after sorting data(teams) and get the sorted result in Unity

 

 Hi,


I'm in the GetMyTeamsResponse cloud code:

 

// ====================================================================================================
//
// Cloud Code for GetMyTeamsResponse, write your code here to customize the GameSparks platform.
//
// For details of the GameSparks Cloud Code API see https://docs.gamesparks.com/
//
// ====================================================================================================
function sortByTeamType(a,b) {
   if (a["teamType"]== b["teamType"])
        return a;
    return 0;
}
function compareValues(key, order) {
  return function(a, b) {
    if(!a.hasOwnProperty(key) || 
       !b.hasOwnProperty(key)) {
  	  return 0; 
    }
    
    const varA = (typeof a[key] === 'string') ? 
      a[key].toUpperCase() : a[key];
    const varB = (typeof b[key] === 'string') ? 
      b[key].toUpperCase() : b[key];
      
    comparison = 0;
    if (varA > varB) {
      comparison = 1;
    } else if (varA < varB) {
      comparison = -1;
    }
    return (
      (order == 'desc') ? 
      (comparison * -1) : comparison
    );
  };
}

var request = new SparkRequests.GetMyTeamsRequest();
var response = request.Send();


//Sort by name -- Here I try to update the teams but it's not working...
response.teams=response.teams.sort(compareValues("teamName","asc"));
var sortedTeams=response.teams.sort(compareValues("teamName","asc"));
//I'm passing the result on scriptdata and it's working
Spark.setScriptData("teams", sortedTeams);

 

 


My question : How to update response.teams without the using of scriptdata?

Other question : Is there a better way to sort the result of the response.team and give the result to Unity ?

 


 Rgds


Login to post a comment