PDA

View Full Version : highscore table


ryrocks
12-06-2008, 08:47 PM
Hey,
I'm trying to make a highscore table for a game in AS3. The table is very basic, only displaying the user name and their score, I therefore don't think it warrants a database. Is there a way of storing these variables in a text file, sorting them in descending order and then displaying the top 10?
I'll probably have to take a different route, but I have so far managed to display variables from a text file:

var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
loader.addEventListener(Event.COMPLETE, loading);
loader.load(new URLRequest("scores.txt"));

function loading (event:Event):void {
boxname_1.text = loader.data.name_1
boxscore_1.text = loader.data.score_1
}

Text file code:
name_1=David:&score_1=100

Any help or advise would be much appreciated.

-Ryan

JimRowan
12-06-2008, 11:03 PM
I would put them in a txt file and have flash parse it like it's XML. Store the scores in an array, and then do a comparison to each score(a binary search would be your best bet, but for complexity's sake, just compare each score).

when your score is greater than a score in the xml file, save that node position.

when it's done parsing, if your node position is greater than 0, than you know your new high score needs to be on that table.(initialize myScorePosition:int =-1); Then, in another for loop, shift down all the scores until you reach myScorePosition, and then just place your score into that node.