Game Development Reference
In-Depth Information
//Submitting the score if the score is higher than the minimum
score of the database
if (scores >= int_minScore) {
var a_newData : Array = new Array(as_users);
//Removing the last Array
a_newData.Pop();
//Create new user and save it to array
var obj_user : UsersData = new UsersData();
obj_user.Init(name, scores);
a_newData.Add(obj_user);
//Setting JS Array back to Builtin
as_users = a_newData.ToBuiltin(UsersData);
//Sorting Data
SortUser(as_users);
}
for (var i: int = 0; i < int_maxUser; i++) {
as_users[i].SaveLocal(i);
}
}
//Sorting the score from the maximum to minimum
private function SortUser (array : UsersData[]) : void {
for (var i : int = 0; i < array.length-1; i++) {
for (var j : int = i+1; j < array.length; j++) {
//If the first score is lower than second score swap the
position
if (array[i].GetScore() <= array[j].GetScore()) {
var obj_temp : UsersData = array[i];
array[i] = array[j];
array[j] = obj_temp;
}
}
}
}
}
7. We will add two more funcions for geing the user score and name from the index
to use it to display on the menu after the SortUser (array : UsersData[])
funcion, as shown in the following code:
class LocalHiScore {
//Above Script
//////////////////////////
//Sort the score from the maximum to minimum
 
Search WWH ::




Custom Search