mIRC Home    About    Download    Register    News    Help

Print Thread
#138311 28/12/05 12:53 PM
Joined: Dec 2005
Posts: 8
D
danago Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
D
Joined: Dec 2005
Posts: 8
hey. Im fairly new to mirc, but experienced enough to understand most commands.

At the moment im working on a trivia bot. Its pretty much complete, except for the highscore system. Currently, im using an external .txt file to store the scores of each user. The file is set out like below:

name x
name x
name x
name x
name x

Where name is the persons username, and x is their score in the game. I am really clueless as to how i can sort all of the scores into a descending list of values.

Just recently, i have also discovered hash tables. I really like them, and they seem much more convenient than constantly getting data from external text files. I know basically how to create, save, load, free, extract data, but i am still unsure how to sort all of the data in a table into a descending list of values.

If anyone has any idea how i might be able to do this, either using my current scoring system with text files. or with hash tables, please post here. All help is greatly appreciated.

Thanks,
Dan.

#138312 28/12/05 02:17 PM
Joined: Oct 2005
Posts: 1,741
G
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
The easiest way is probably to load all of the scores from the file into a custom window that has the -s switch set.

alias sortscores {
window -ls @scores
var %r, %c = 0, %c = $lines(scores.txt)
while (%c < %cc) {
inc %c
tokenize 32 $read(scores.txt,%c)
aline @scores $2 $1
}

echo -s Top Score: $line(@scores,1)
}

This is a simple (untested) code to sort the scores. The blue part may need to be modified depending on how your scores are stored.

-genius_at_work

#138313 28/12/05 05:22 PM
Joined: Aug 2005
Posts: 525
S
Fjord artisan
Offline
Fjord artisan
S
Joined: Aug 2005
Posts: 525
Maybe I'm missing something, but wouldn't the simplest method be to just use filter? Easy as pie.

/filter -ffctue 2 32 scores.txt scores.txt

This will sort the file according to the scores from highest to lowest.

Change the filename.

#138314 28/12/05 06:38 PM
Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
Custom windows with the -s switch do an alphabetic sort, not a numeric sort. Easiest is to use a filter like schaefer did.


Gone.
#138315 29/12/05 03:46 AM
Joined: Dec 2005
Posts: 8
D
danago Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
D
Joined: Dec 2005
Posts: 8
Quote:
Maybe I'm missing something, but wouldn't the simplest method be to just use filter? Easy as pie.

/filter -ffctue 2 32 scores.txt scores.txt

This will sort the file according to the scores from highest to lowest.

Change the filename.


Thank you very much. That works perfectly smile


Link Copied to Clipboard