|
darkspot Apprentice
Joined: 29 Jul 2002 Posts: 105
|
Posted: Sat Sep 18, 2004 12:18 am
Organizing a String list |
I want to know how to add to a string list and keep it in alphabetical order.
If I have the list
#var Damagedeq {Big Sword|Medium Shield|Bone Shield|Leather Belt} Is there any way as I'm inserting the different strings to put them in alphabetical order? so it'd turn out as
#var Damagedeq {Big Sword|Bone Shield|Leather Belt|Medium Shield}
right as I added them.
This would also likely bring up string lists such as
#var Damagedeq {Big Sword|Big Sword|Big Sword|Bone Shield|Bone Shield|Medium Shield}
With multiple entries of the same item. Is there any way to Make it go one step further beyond alphabetized to
#var Damagedeq {3,Big Sword|2,Bone Shield|1,Medium Shield} or any other format (1XBig sword, or 1|Big Sword) Thanks for any help. |
|
|
|
nexela Wizard
Joined: 15 Jan 2002 Posts: 1644 Location: USA
|
Posted: Sat Sep 18, 2004 2:10 am |
Doing this to the variable is alot harder then it would be to just format the display of the var using zmuds %functions.
To sort
#VAR Damagedeq {Big Sword|Medium Shield|Bone Shield|Leather Belt}
#SAY %sort(@Damagedeq)
To count and sort multi-line
#loopdb %countlist(%sort(@damagedeq)) {#say %key %val}
count and sort single line
#say %expanddb(%countlist(%sort(@damagedeq)),",","=") |
|
|
|
LightBulb MASTER
Joined: 28 Nov 2000 Posts: 4817 Location: USA
|
Posted: Sat Sep 18, 2004 3:44 pm |
For a sorted list, just make your list as usual then sort it once after you've entered all your items. You can put the command in alias to make it easier. You can also sort the list after adding items.
Code: |
#VAR Damagedeq {Big Sword|Medium Shield|Bone Shield|Leather Belt}
#VAR Damagedeq %sort( @Damagedeq)
#AL slist {#VAR %1 %sort( @%1)} |
For a sorted and counted list, use %countlist and %sort. This can also be put in an alias for ease of use.
Code: |
#VAR Damagedeq {Big Sword|Medium Shield|Bone Shield|Big Sword|Leather Belt|Bone Shield|Big Sword}
#VAR Damagedeq %expanddb( %countlist( %sort( @Damagedeq)), |, ",")
#AL clist {#VAR %1 %expanddb( %countlist( %sort( @%1)), |, ",")} |
To use the aliases, put the variable's name without the @.
slist Damagedeq
clist Damagedeq
NOTE: Once a list has been counted, it will need to be remade before counting again. Big Sword isn't the same as Big Sword,3 so if you added another Big Sword without remaking the variable you'd end up with Big Sword,1|Big Sword,3,1. Personally, I prefer record variables for keeping counts. |
|
_________________ LightBulb
Senior member
Most scripts in this forum are written for Command Line entry.
Don't even open the Settings Editor unless its use is specified or obvious. |
|
|
|
|
|
|
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
|
|