Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD Beta Forum
DanteX
Apprentice


Joined: 13 Aug 2007
Posts: 166

PostPosted: Sun Aug 26, 2007 6:10 pm   

[2.01] %sort not sorting in numerical order
 
This piece of code gives me this output:
Code:
#ALIAS testalias($number) {
$FirstAmmount=0
$SecondAmmount=0
$ThirdAmmount=0
$first=0
$second=0
$third=0
#LOOP $number {
TestArray=""
$time=%secs
#LOOP 10000 {#IF (@test) {} {}}
$first=( %secs-$time)
#SHOW FIRST: $first
$time=%secs
#LOOP 10000 {#IF (%DB( @testvar, test)) {} {}}
$second=( %secs-$time)
#SHOW SECOND: $second
$time=%secs
#LOOP 10000 {#IF (@testvar.test) {} {}}
$third=( %secs-$time)
#SHOW THIRD: $third
#ADDITEM TestArray $first
#ADDITEM TestArray $second
#ADDITEM TestArray $third
#SHOW TestArray @TestArray
#SHOW SortedTestArray: %sort(@TestArray)
}
}


gives me this output

FIRST: 141
SECOND: 1203
THIRD: 938
TestArray 141|1203|938
SortedTestArray: 1203|141|938

The %sort function doesn't sort array in numerical order, but alphabetical.

D
Reply with quote
Rorso
Wizard


Joined: 14 Oct 2000
Posts: 1368

PostPosted: Sun Aug 26, 2007 6:31 pm   Re: [2.01] %sort not sorting in numerical order
 
DanteX wrote:

The %sort function doesn't sort array in numerical order, but alphabetical.

I think that is intended.

From the help files:
"Syntax: %sort(list,dir)

returns the list with items sorted in alphabetical order. If dir is missing or zero, list is sorted in ascending order. If dir is non-zero, list is sorted in descending order. "
Reply with quote
Larkin
Wizard


Joined: 25 Mar 2003
Posts: 1113
Location: USA

PostPosted: Mon Aug 27, 2007 1:44 am   
 
Yes, it is intentional, and that's why you need to prepend numbers with zeros and pad it out as a fixed-length string. Would be nice to have an option on %sort to sort numerically, now that we can have more specifically typed variables.
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Mon Aug 27, 2007 6:53 pm   
 
I'll add this to the wish list to see if I can come up with a way to add an optional argument to %sort.

Just remember that these are *not* "arrays"...they are *string* lists. That means that each value in the list is a *string* value.
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD Beta Forum All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net