Author Topic: Coding highscores, and I'm currently stumped.  (Read 628 times)

Code: [Select]
%count = 0;
while(!%file.isEOF())
{
%line[%count] = %file.readLine();
%count++;
}
%file.close();
%file.delete();

while(%count != 0)
{
%high = ""; // resetting the variable
for(%i=0;%i<%count;%i++)
if(getField(%line[%count],1) >= getField(%high,1))
%high = %line[%count]; // if the score is higher than the previously checked score, set %high to the new line

%data = new ScriptObject(HighscoreData)
{
bl_id = getField(%high,0);
score = getField(%high,1);
};
CrumbleHighscoreList.add(%data); // add that line to the set

for(%j=%i;%j<%count;%j++)
%line[%count] = %line[%count-1]; // and remove it from local variables

%count--;
}

Was wanting to just sort everything as it's added to the set.

Right now it's just adding lines to the set as it gets to them, e.g.
Code: [Select]
18701 456
28394 785
98404 256
102931 1023
39303 493
39485 394
4742 125
would output that in reverse, and minus the last line

I have no idea what you're doing

//store score
$HighScores[%client.bl_id] = %client.score;
//save score
export("$HighScores*", "config/highscores.cs");
//load score on server start
exec("config/highscores.cs");

Done

trying to sort them...
i'm not trying to save them...


Bubblesort is really inefficient, but it does get the job done. Try implementing quicksort if you can, it's just a bit complicated.


Code: [Select]
for(%i=0;%i<%count;%i++)
{
%high = "";
%selected = "";
for(%j=0;%j<%count;%j++)
{
echo(%line[%j]);
if(getField(%line[%j],1) >= getField(%high,1))
{
%selected = %j;
%high = %line[%j];
}
}
%data = new ScriptObject(ScoreData)
{
bl_id = getField(%high,0);
score = getField(%high,1);
};
CrumbleHighscoreList.add(%data);
%line[%selected] = "";
}
this works. Thanks for the help guys.

EDIT:
Code: [Select]
%sorter = new GuiTextListCtrl(){};
for(%i = 0; %i < %count; %i++)
%sorter.addRow(%i, %line[%i]);
%sorter.sortNumerical(0,0);
for(%i = 0; %i < %sorter.rowCount(); %i++)
echo(%sorter.getRowText(%i));
%sorter.delete();
That appears to be a lot more efficient, thanks Ip.
« Last Edit: April 17, 2014, 08:56:57 PM by TheBlackParrot »