|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4691 Location: Pensacola, FL, USA
|
Posted: Sat Jun 14, 2008 10:50 pm
[2.27] Sorting local dbvars |
Okay, so i have the following trigger
Code: |
<trigger priority="1" id="555">
<pattern>^{In|On|Under|Behind|Peering into} the (*) you see (*).</pattern>
<value>#GAG
$container=%1
$contents=%subregex(%2 ," and |, ","|")
#SAY %numitems($contents)
$contents=%sort(%countlist($contents))
$contents2=%leftback(%subregex($contents,"(?:(=1)|=(\d+))\|","(?(1)| (x\2)), "),2)
#SAY {$container has:%cr$contents2}</value>
</trigger>
|
It works great, but i want the results sorted by the last word of the %key.
So I found an old thread where I got info on sorting:
http://forums.zuggsoft.com/forums/viewtopic.php?t=23617
And tried to modify it to work with local vars:
Code: |
#LOCAL $gemtemp $gemnumword $gem2 $gem3 $gemsorted
#LOOPDB $contents {
$gemnumword=%numwords( %key)
#WHILE ($gemnumword) {
$gemtemp=%concat(%if($gemtemp, %concat($gemtemp, " ")), %word(%key, $gemnumword))
#ADD $gemnumword -1
}
#ADDK $gem2 {%trimleft( %pop($gemtemp))=%val}
}
$gem3=%sort($gem2)
#SAY $gem3
#SAY ---
$gem2=""
#LOOPDB $gem3 {
$gemnumword=%numwords( %key)
#WHILE ($gemnumword) {
$gemtemp=%concat(%if($gemtemp, %concat($gemtemp, " ")), %word(%key, $gemnumword))
#ADD $gemnumword -1
}
#ADDK $gem2 {%trimleft( %pop($gemtemp))=%val}
}
#SAY $gem2 |
$gem3 displays sorted properly
But i cannot get $gem2 to retain the same order as $gem3 had... is there a way to force the order placement of keys in a local dbvar? Or another way to get the results that i want?
Here is what looking in the container normally looks like.
Code: |
In the battle satchel you see an uncut diamond, some ambrominas leaf, an uncut ruby, a minotaur hoof, a copper lockpick, a minotaur hoof, a green sapphire, some thick lily white gloves, a star ruby, a minotaur hoof, a minotaur hoof, a minotaur hoof, a minotaur hoof, a minotaur hoof, a violet sapphire, a medium grey pearl, a deep purple amethyst, a minotaur hide, a minotaur hide, a minotaur hide, a yellow sapphire, a minotaur hide, a minotaur hide, a medium black pearl, a minotaur hide, a rolton pelt, a green garnet, an uncut emerald, some polished red coral, a white opal, a star ruby, an uncut diamond, a red spinel, a dark red-green bloodstone, a large black pearl, a violet sapphire, a crystal amulet, some polished pink coral, a violet sapphire, an uncut ruby, a piece of golden amber, a pink spinel, a green sapphire, a violet sapphire, some polished pink coral, a medium black pearl, a smoky topaz, a turquoise stone, a medium grey pearl, a large pink pearl, a pink sapphire, a pink sapphire, a green sapphire, a white opal, an aquamarine gem, a pink tourmaline, a star ruby, a piece of citrine quartz, a star sapphire, some blue lapis lazuli, a clear topaz, a green garnet, a green tourmaline, some polished pink coral, some blue lapis lazuli, a star sapphire, a black tourmaline, a piece of rose quartz, a light pink morganite stone, a green tourmaline, a clear zircon, a green tourmaline, a blue tourmaline, a green zircon, a mottled agate, a piece of golden amber, a tiny grey pearl, a black tourmaline, a bright chrysoberyl gem, a turquoise stone, some polished pink coral, a green sapphire, a blue spinel, a piece of golden amber, a dark red-green bloodstone, a star sapphire, a blue topaz, a golden beryl gem, a turquoise stone, a light pink morganite stone, a brown zircon, a green zircon, a bright chrysoberyl gem, a red spinel, a pink tourmaline, a green tourmaline, a pale green moonstone, a shard of rainbow quartz, a green zircon, a green zircon, a piece of citrine quartz, a piece of golden amber, a deep purple amethyst, some blue lapis lazuli, a white opal, a pink spinel, a medium pink pearl, a black tourmaline, a pink tourmaline, a green sapphire, a pink sapphire, a yellow sapphire, a star sapphire, a white opal, a smoky topaz, a medium black pearl, a violet sapphire, a large white pearl, a pink sapphire, an uncut diamond, a blue sapphire, a star sapphire, some polished pink coral, an aged palimpsest, a spiked onyx scarab, a star ruby, an uncut diamond, a white opal, a tiny pink pearl, a star ruby, a white opal, a violet sapphire, a turquoise stone, a star sapphire, a violet sapphire, a quartz crystal, a quartz crystal, a black opal, an uncut ruby, a star ruby, a star ruby, a black opal, a tiny pink pearl, a white opal, an uncut emerald, an uncut diamond, an uncut ruby, a blue sapphire, a yellow sapphire, some polished pink coral, a medium white pearl, a green garnet, a white crystal, a green sapphire, an uncut diamond, a star ruby, a green sapphire, a black opal, a blue spinel, a rolton pelt, a minotaur hide, a rolton pelt, a minotaur hide, a minotaur hide and a minotaur horn. |
|
|
_________________ Discord: Shalimarwildcat |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Sat Jun 14, 2008 11:11 pm |
There's no such thing as sorting a dbvar any more. They're stored as hashes. You'll need to find some other way of doing it, probably by building a stringlist whose items are the keys of the db, which you then loop through in order, accessing the dbvar with %db to get the number.
|
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4691 Location: Pensacola, FL, USA
|
Posted: Sun Jun 15, 2008 3:39 am |
Okay, so i went in and did as you said to get this:
Code: |
<trigger priority="1" id="555">
<pattern>^{In|On|Under|Behind|Peering into} the (*) you see (*).</pattern>
<value>#GAG
$container=%1
$contents=%subregex( %2 , " and |, ", "|")
#SAY %numitems( $contents)
$contents=%sort( %countlist( $contents))
$contents2=%leftback( %subregex( $contents, "(?:(=1)|=(\d+))\|", "(?(1)| (x\2)), "), 2)
#SAY {$container has:%cr$contents2}
$contents2=""
#LOCAL $sortFront $sortBack $temp
#LOOPDB $contents {
$numword=%numwords( %key)
#WHILE ($numword) {
$temp=%concat( %if( $temp, %concat( $temp, " ")), %word( %key, $numword))
#ADD $numword -1
}
#ADDI $sortBack {%pop( $temp)}
}
$sortBack=%sort( $sortBack)
#FORALL $sortBack {
$numword=%numwords( $sortBack)
#WHILE ($numword) {
$temp=%concat( %if( $temp, %concat( $temp, " ")), %word( %i, $numword))
#ADD $numword -1
}
#ADDI $sortFront {%pop( $temp)}
}
#FORALL $sortFront {$contents2=%concat( %if( $contents2, %concat( $contents2, ", ")), %i, %if( %db( $contents, %i)>1, %concat( " (x", %db( $contents, %i), ")")))}
#SAY New output:%cr$contents2</value>
</trigger>
|
Anyway i can improve the speed of this script?
I would attempt to do the new section with a subregex like the old, but i still havent got the hang of regex in general. |
|
_________________ Discord: Shalimarwildcat |
|
|
|
|
|
|
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
|
|