Hello every one
I have 2 items one of them is "count" and other one is "time".
I try to compare time with saved times and rate them in array.
this script should compare "Time" and rate & if they (times) are same compare "count" and rate them.
I made this script but this script do not work properly!!
All of the numbers saved in first raw and it couldn't replace the older one to down or up
#pragma strict
// currently saved time and count
static var CSTime : int;
static var CSCount : int;
// All times and counts that saved before.
var ATime = new int[6];
var ACount = new int[6];
static function Compare () {
// this loop try to compare time results from 0 to 6
// its start from raw 1 and Compare it with recent of there is be some thing like that
// will save it there else compare values to decide to go next raw or replace new score.
for( var i : int = 0; i < 6 ; i ++){
// i = each row of High Scores ;)
// if that row is empty lets add it there
if(!PlayerPrefs.HasKey("Time"+i ) && PlayerPrefs.GetInt("Time"+i) != 0 && PlayerPrefs.GetInt("Count"+i) != 0){
PlayerPrefs.SetInt("Time"+i , CSTime);
PlayerPrefs.SetInt("Count"+i , CSCount);
break;
}
else{
//check older results with recent record and know it's not better than that
if( CSTime <= PlayerPrefs.GetInt("Time"+i) && CSCount <= PlayerPrefs.GetInt("Count"+i)){
//if recent is better we should send the weaker results to lawer ranks.
for( var n : int = 6 ; n < i ; n--){
var m : int ;
if(i == 6){
//if we are in 7 then couldn't replace anything.
break;
}
//at this style script start from number 7 and replace down raws with upward raws.
//Till "n" raw arrive "i" and then place i in his real place.
PlayerPrefs.SetInt("Time"+n , PlayerPrefs.GetInt("Time"+(n-1)));
}
PlayerPrefs.SetInt("Time"+i , CSTime);
PlayerPrefs.SetInt("Count"+i , CSCount);
break;
}
}
}
}
Could you help me to rewrite it , please
thanks in advance.
↧