mIRC Home    About    Download    Register    News    Help

Print Thread
#99088 28/09/04 09:00 PM
D
dragonslayere
dragonslayere
D
how would i go about sorting vars by their values
ex:

%var1 2
%var2 5
%var3 4
%var4 1
%var5 3

will sort out to

%var4 1
%var1 2
%var5 3
%var3 4
%var2 5

#99089 29/09/04 04:38 AM
Joined: Mar 2003
Posts: 1,256
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Mar 2003
Posts: 1,256
Sorting the variables is kinda obsolete, as sorting different variables on their value is a bit weird. There are ways to sort, but you would somehow need to store the different variable names as well. What I would suggest is open a sorted window, dump the values in it, they will be sorted, and extract the sorted list from there.

Perhaps if you describe what you intend to do here, we could suggest alternate ways...

#99090 29/09/04 05:33 AM
Joined: Dec 2002
Posts: 787
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 787
Sortting variables is only 'obsolete' if you have no purpose for doing so..

dragonslayere; if you actually are wanting to sort the variable listing in the script editor (ALT+R), you can use something like;

alias sortvar {
var %i = $calc($var(*,0) + 1)
window -ehs @sort.hidden
clear @sort.hidden
while (%i) {
aline @sort.hidden $+($eval($var(*,%i),2),&,$var(*,%i))
dec %i
}
unsetall
var %o = 1
while ($line(@sort.hidden,0) >= %o) {
set -n $gettok($line(@sort.hidden,%o),-1,38) $gettok($line(@sort.hidden,%o),$+(1-,$calc($0 - 1)),38)
inc %o
}
window -c @sort.hidden
}

Simply, /sortvar.

Eamonn.

#99091 29/09/04 11:59 PM
D
dragonslayere
dragonslayere
D
err i have no clue what u posted...

maybe this will be easier to do
sortying the values in vars

%var 1 3 2 4
to
%var 12 3 4

#99092 01/10/04 03:42 PM
Joined: Feb 2004
Posts: 2,013
F
Hoopy frood
Offline
Hoopy frood
F
Joined: Feb 2004
Posts: 2,013
%var = $sorttok(%var,32,n)

/help $sorttok

Greets


Link Copied to Clipboard