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
fattony
Apprentice


Joined: 27 Dec 2001
Posts: 105
Location: USA

PostPosted: Thu Aug 15, 2002 6:40 pm   

Putting Numbers In Order
 
Is there an easy way to place check a group of numbers (contained in variables), and place them in order? (highest to lowest or vice versa) I need to order a list of variables using the #if command, if possible.

Fat Tony
Reply with quote
TonDiening
GURU


Joined: 26 Jul 2001
Posts: 1958
Location: Canada

PostPosted: Thu Aug 15, 2002 9:32 pm   
 
%additem them together into a list then use %min or %max?

Ton Diening
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5187

PostPosted: Thu Aug 15, 2002 11:14 pm   
 
You can also use the %sort function to put them in order. The sort function will not look any deeper then the text value of the items in the list, and sorts by alpha precedence so a numeric list would come out 1|10|11|12|13|14|2|3|4|5|6|7|8|9 which means you would have to zero fill if you want to do a numeric sort.

Perhaps if you got really specific about what you want to do, then we could get really specific about how to do it.
Reply with quote
fattony
Apprentice


Joined: 27 Dec 2001
Posts: 105
Location: USA

PostPosted: Fri Aug 16, 2002 3:17 am   
 
I have a list of 5 lines (a mastery system) that I would like to display in order of advancement. This is the list, though most of the information is not relative.

#say Sword: %format( "&9.0n", @ran_swd).@ran_swordtimen ~{@ran_swdmsg~} -=- Advance: @ran_swordtime
#say Axe: %format( "&11.0n", @ran_axe).@ran_axetimen ~{@ran_axemsg~} -=- Advance: @ran_axetime
#say Bow: %format( "&11.0n", @ran_bow).@ran_bowtimen ~{@ran_bowmsg~} -=- Advance: @ran_bowtime
#say Beastmastery: %format( "&2.0n", @ran_bst).@ran_beasttimen ~{@ran_bstmsg~} -=- Advance: @ran_beasttime
#say Wilderness: %format( "&4.0n", @ran_wld).@ran_wildtimen ~{@ran_wldmsg~} -=- Advance: @ran_wildtime

I have a list of the (@ran_swd,@ran_axe,@ran_bow,@ran_bst,@ran_wld). Those are all numeric, each number being between 1 and 20. I need to be able to sort those in numeric order, and then use #if's to display each corresponding line relative to its mastery level.

Ex- ran_swd = 16, ran_axe = 2, ran_bow = 10, ran_bst = 11, and ran_wld = 9 --- would come out like:

#say Sword: %format( "&9.0n", @ran_swd).@ran_swordtimen ~{@ran_swdmsg~} -=- Advance: @ran_swordtime
#say Beastmastery: %format( "&2.0n", @ran_bst).@ran_beasttimen ~{@ran_bstmsg~} -=- Advance: @ran_beasttime
#say Bow: %format( "&11.0n", @ran_bow).@ran_bowtimen ~{@ran_bowmsg~} -=- Advance: @ran_bowtime
#say Wilderness: %format( "&4.0n", @ran_wld).@ran_wildtimen ~{@ran_wldmsg~} -=- Advance: @ran_wildtime
#say Axe: %format( "&11.0n", @ran_axe).@ran_axetimen ~{@ran_axemsg~} -=- Advance: @ran_axetime


I hope that makes some sense. The %min/%max idea might work, but isn't too efficient. I was thinking a combination of %max and %pop but I can't figure out a good way to do it.

Fat Tony
Reply with quote
TonDiening
GURU


Joined: 26 Jul 2001
Posts: 1958
Location: Canada

PostPosted: Fri Aug 16, 2002 4:22 am   
 
How about something then like this:

#ALIAS SortAndSpew {
#VARIABLE List {%format("&3.0n",@ran_swd)_ran_swd|%format("&3.0n",@ran_axe)_ran_axe|%format("&3.0n",@ran_bow)_ran_bow|%format("&3.0n",@ran_bst)_ran_bst|%format("&3.0n",@ran_wld)_ran_wld}

#VARIABLE List %sort( @List, 1)

#FORALL @List {%copy( %i, %pos( "_", %i)+1, %len( %i))}
}

Then you have an alias for each like:
#ALIAS ran_swd {#say Sword: %format( "&9.0n", @ran_swd).@ran_swordtimen ~{@ran_swdmsg~} -=- Advance: @ran_swordtime}

etc...

Ton Diening

Edited: See below for nicer solution
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5187

PostPosted: Fri Aug 16, 2002 4:32 am   
 
Your variable naming lends this to an indirect functioning. It gets kinda messy, but is cleaner then the series of #IF that would be required to display them after sorting.

#AL SortVars {SortList="";#ADDITEM SortList {%replace(%format("&2.0n",@ran_swd)," ","0") ran_swd};#ADDITEM SortList {%replace(%format("&2.0n",@ran_axe)," ","0") ran_axe};#ADDITEM SortList {%replace(%format("&2.0n",@ran_bow)," ","0") ran_bow};#ADDITEM SortList {%replace(%format("&2.0n",@ran_bst)," ","0") ran_bst};#ADDITEM SortList {%replace(%format("&2.0n",@ran_wld)," ","0") ran_wld};SortList=%sort(@SortList,1)}

Now for the display:
#VAR ran_axenam "Axe"
#VAR ran_swordnam "Sword"
#VAR ran_bownam "Bow"
#VAR ran_bstnam "Beastmaster"
#VAR ran_wldnam "Wilderness"
#AL Display {CurrentItem=1;#WHILE (@CurrentItem<6) {CurrentVar=%word(%item(@SortList,@CurrentItem),2);#say %format("&13s",@{@{CurrentVar}nam}): @{@{CurrentVar}}.@{@{CurrentVar}timen} ~{@{@{CurrentVar}msg}~} -=- Advance: @{@{CurrentVar}time};#ADD CurrentItem 1}}

You will have to combine the 2 how you want and rename a few of the variables so they are consistent. Also I moved the space padding provided by format to the first part, so that the number used will not have to be varied. Further formats might be required to make perfect columns.
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