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

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » zMUD General Discussion
Rorso
Wizard


Joined: 14 Oct 2000
Posts: 1368

PostPosted: Sun Dec 21, 2003 5:16 pm   

Sorting a record :)
 
Hello,

I wonder how you could sort a record into a list.

The record looks something like this:
Code:

a sword         12
some armour     2 
a bag           1
a small stone   22


This should be sorted into:
a small stone|a sword|some armour|a bag

Thanks for helping me Smile
Reply with quote
Danlo
Magician


Joined: 28 Nov 2003
Posts: 313
Location: Australia

PostPosted: Mon Dec 22, 2003 9:49 am   
 
I am assuming the 2 fields are called Name and Value. I had a problem with this, whereby %dbmax() didn't set %rec to the record with the maximum Value. Hopefully, if you use the newest version, it should be ok.

#var sortedrecords {%null}
#var recordvalues {%null}
#LOOP %numrec() {#NOOP {%dbmax(value)}
#var sortedrecords {%additem(%db(%rec,name),@sortedrecords)}
#var recordvalues {%additem(%db(%rec,value),@recordvalues)}
#addkey Value 0}
#DBRESET
#FORALL @sortedrecords {#LOOPVIEW {#IF (%db(%rec,Name) = "%i") {#addkey Value %item(@recordvalues,1)
#delnitem recordvalues 1} {}}
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD General Discussion 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