runescape=crap
Still Fresh
- Joined
- May 11, 2005
- Messages
- 61
I was planning on trying to put a score board in my game and was wondering if anyone can suggest the best way to do it.
global
array[10]; //an array, the number tells how big the array is.
pointscounter; //the score you achieve during gameplay
...
process highscore();
private
n; //variables you need for the sorting
i; // ~
j; // ~
t; // ~
begin
load("config.cfg",array); //load values from the file config.cfg into the array (one value for each number)
n=10; //How big your highscore is (10 entries)
i=1; //leave that as it is
j=i+1; //leave that as it is
if(array[10]<pointscounter) //if score is higher then number 10 of the highscore
array[10]=pointscounter; // then your score=place ten in highscore, and start sorting
while(i<=n); //here starts the highscore sorting
while(j<=n);
if(array[i]<array[j])
t=array[j];
array[j]=array[i];
array[i]=t;
end;
j++;
end;
i++;
j=i+1;
end; //here does the sorting end
end;
save("config.cfg",array); //save the highscore in config.cfg afterwards
end;
Global
// 10 entries(Fenix declares both 0 and 9 for some reason)
scoreTable[9] = 1000,900,800,700,600,500,400,300,200,100;
...
/**
* Loads highscore table from file into the array where it belongs
*/
process loadScores()
begin
if(file_exists("scores.dat"))
load("scores.dat",scoreTable);
end
end
/**
* Saves highscore table to a file
*/
process saveScores()
begin
save("scores.dat",scoreTable);
end
/**
* Tries to add a score to the table, returns the new scores' position in the list(starting with 1) if succeeded, -1 if not added.
*/
process addScore(myScore)
private
i,j;
begin
//Goes through the table until it finds a score below the score to be added
for(i = 0; i < 10; i++)
if(scoreTable[i] < myScore)
break;
end
end
//Moves all scores from the detected one downwards one step down
for(j = 8; j >= i; j--)
scoreTable[j+1] = scoreTable[j];
end
//And adds the new score on the open position.
if(i <= 9)
scoreTable[i] = myScore;
return(i+1);
else
return(-1);
end
end
eh?Moogle posted on May 16 2005 at 06:52 PM said:Throw them in a struct or array and save that.