|
adamwalker Apprentice
Joined: 12 Mar 2005 Posts: 195
|
Posted: Thu Apr 21, 2005 6:23 pm
Simple variable sorting problem |
I have a very simple problem thats turning out to be a pain...
I have 2 variables...
@badmonsterlist = man|woman|warg|boy|demon|warg|warg
and
@orderofattack = warg|boy|man|demon
what i would like to do is SORT @badmonsterlist according to the list defined in @orderofattack
thankyou for your time!! |
|
|
|
Vijilante SubAdmin
Joined: 18 Nov 2001 Posts: 5182
|
Posted: Thu Apr 21, 2005 9:40 pm |
I really can't see the point of sorting it since you already have a sorted list. A simple counter variable with testing for the presence of the keyword would suffice. In any case, a sorting snippet:
BML=%countlist(@badmonsterlist)
badmonsterlist=""
#FORALL @orderofattack {
#IF (%iskey(@BML,"%i")) {
#LOOP %db(@BML,"%i") {badmonsterlist=%additem("%i",@badmonsterlist)}
#DELKEY BML {%i}
}
}
#LOOPDB @BML {#LOOP %val {badmonsterlist=%additem(%key,@badmonsterlist)}}
#UNVAR BML |
|
_________________ The only good questions are the ones we have never answered before.
Search the Forums |
|
|
|
adamwalker Apprentice
Joined: 12 Mar 2005 Posts: 195
|
Posted: Thu Apr 21, 2005 9:53 pm WOW! |
Fantastic and fast reply. thats exactly what i needed
the reason a count wouldnt do is because i would then use that to target them in order, there is a tactical advantage from that.
then i can target each and trigger when it dies to remove the first item in the string!
thanks again |
|
|
|
Maelstrom Apprentice
Joined: 10 Feb 2005 Posts: 158
|
Posted: Thu Apr 21, 2005 10:09 pm |
Well crap :) got beat to the punch... sigh
Oh well as long as I already made something... might as well post it. I like yours better Vij
#FORALL @badmonsterlist {#VAR sortedlist {%additem(%ismember(%i,@orderofattack),@sortedlist)}}
#DELITEM sortedlist {0}
#VAR sortedlist {%sort(@sortedlist)}
#LOOP 1,%len(@sortedlist) {#VAR sortedlist %replaceitem(%item(@orderofattack,%item(@sortedlist,%i)),%i,@sortedlist)} |
|
|
|
adamwalker Apprentice
Joined: 12 Mar 2005 Posts: 195
|
Posted: Thu Apr 21, 2005 10:24 pm nice! |
thankyou both for your efforts, ill try yours out too maelstrom.
Heres how i strung everything together if you are curious...
You do INFO HERE.. which gives an output of
--> Clear @demonlist
"imp22270" a slime demon.
"pestilence22270" a slime demon.
"pestilence22270" a slime demon.
"slime22270" a slime demon.
--- > alias DEMONSORT
which triggers
Quote: |
pattern - ~"(%w)(%d)~"(*)
value - #if (%ismember( %1, @demonorder)) {#var demonlist %additem( %1, @demonlist)}
|
variable demonorder contains
Quote: |
@demonorder = Possession|pestilence|imp|parasite|leech|slime|Balrog
|
Alias demonsort is the wonderfull code Vijilante gave
Quote: |
DML=%countlist( @demonlist)
demonlist=""
#FORALL @demonorder {
#IF (%iskey( @DML, "%i")) {
#LOOP %db( @DML, "%i") {demonlist=%additem( "%i", @demonlist)}
#DELKEY DML {%i}
}
}
#LOOPDB @DML {#LOOP %val {demonlist=%additem( %key, @demonlist)}}
#UNVAR BML
|
So all that strung together gives a nicely sorted demonlist.
A small problem was that it gave an output of
@demonlist = |pestilance|pestilance|imp|slime
That means there was a blank entry at the start. so when doing the attack it would firstly attack nothing, rather then using the first entry i just used and delted the 2nd.
ls project %item( @demonlist, 2)
#DELNITEM demonlist 2 <--- so i could move onto the next little sucker
sorry if this long string makes no sense... but it works. which is what matters. thanks again to you both
if anyone is curious this is for AVALON mud |
|
|
|
|
|