|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4692 Location: Pensacola, FL, USA
|
Posted: Mon May 29, 2006 8:06 am
Inverse sorting |
Okay, i have a database variable @mykills like so:
rough bodyguard: 1
short merchant: 1
tall bodyguard: 1
grumpy dwarf warrior: 1
hardworking dealer: 1
young cold eyed fighter: 1
impassioned fighter: 1
whispering fighter: 1
squinty eyed fighter: 1
ugly fighter: 1
cross-eyed fighter: 1
wandering hunter: 1
old dwarf warrior: 4
stocky dwarf warrior: 2
scowling hunter: 1
angry dwarf warrior: 1
fat dwarf warrior: 2
burly dwarf warrior: 2
young dwarf warrior: 1
watchman: 1
proud deckhand: 1
broad-shouldered seafarer: 1
good-natured warrior: 1
And continually expanding.
Now then, i want to sort these by the name of the record within the variable, starting with the last name, then the next to last (if numwords>2), and finally, by whatever is left at the beginning, if anything.
The number of words it the record name is variable (1-6). |
|
_________________ Discord: Shalimarwildcat |
|
|
|
edb6377 Magician
Joined: 29 Nov 2005 Posts: 482
|
Posted: Wed May 31, 2006 2:33 am |
need to know if this is a true zmud database or a data record.. it makes a big difference.
|
|
_________________ Confucious say "Bugs in Programs need Hammer" |
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4692 Location: Pensacola, FL, USA
|
Posted: Wed May 31, 2006 5:15 am |
its a database variable as per the help files, but it is not a true database, just key-value pairs, im trying to sort the keys (and keep the proper value of course)
|
|
_________________ Discord: Shalimarwildcat |
|
|
|
edb6377 Magician
Joined: 29 Nov 2005 Posts: 482
|
Posted: Wed May 31, 2006 7:36 am |
okay so its a data record variable. More complicated i will see what i can dig up.
You can use #LOOPDB to loop through and get teh %key of each variable record entry that gives you the names without the numbers then its just a matter of sorting that information.. It will take a bigger string to sort it all out. My guess is you will have to use a numwords value then split it by that value to reverse the entries in sorting and then do the set of commands again to put it back in the right order. I will work on it later.
i.e.
compassioned fighter becomes fighter compassioned the list is then sorted and then you flip them around again
So it would seem you would do sometime similar to
GRAB THE NUMWORDS VALUE
REVERSE THE WORDS into @mykills temp
%sort(@mykillstemp,1)
Reverse mykills temp into mykills variable
and your list will be sorted the way you want in theory anyways. |
|
|
|
edb6377 Magician
Joined: 29 Nov 2005 Posts: 482
|
Posted: Wed May 31, 2006 9:25 am |
Okay this is merely a starting point for you. it works but could use some optimization as i wrote it kinda hastily. I will work on it more later but its 5:30am give or take right now and im tired now :) I left out the MYKILLS variable since its the one you already have setup. Whenever it is called by typing the alias mykillssort (RENAME IT WHATEVER) it will sort the mykills data record variable into mykills3 datarecord variable. What this means is no changing your recorded kills script but it will output a sorted datarecord for your review. Easily showed by typing
#SHOWDB @mykills3 <-- i currently have this script doing it. If you dont want it to display everytime you sort it then you can do it somewhere else.
Code: |
#CLASS {ZUGGTEST} {enable}
#ALIAS mykillssort {
#VARIABLE mykills3 %null
#LOOPDB @mykills {
#MATH mykillnumword (%numwords( %key)-0)
#WHILE (@mykillnumword > 0) {
#ADD mykilltemp (" "%word( %key, @mykillnumword))
#MATH mykillnumword @mykillnumword-1
}
#ADD mykills2 %trimleft( @mykilltemp)"="%val"|"
#VARIABLE mykilltemp %null
#VARIABLE mykillnumword %null
}
#VARIABLE mykillnumword %numwords( %sort( @mykills2, 1), "|")
#WHILE (@mykillnumword > 0) {
#ADDKEY mykills3 {%word( %sort( @mykills2, 1), @mykillnumword, "|")}
#MATH mykillnumword @mykillnumword-1
}
#UNVAR mykills2
#SHOWDB @mykills3
}
#VARIABLE mykillnumword {0}
#VARIABLE mykilltemp {}
#CLASS 0
|
|
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4692 Location: Pensacola, FL, USA
|
Posted: Wed May 31, 2006 5:29 pm |
Okay, that sorts it great.
But all the strings are back to front.
Is there a way to return the strings to how the looked previous to sorting yet still remail sorted? |
|
_________________ Discord: Shalimarwildcat |
|
|
|
Ceres Wanderer
Joined: 25 May 2006 Posts: 88
|
Posted: Thu Jun 01, 2006 3:52 am |
As they are usually decoritive I would be tempted to strip out the descriptive terms keeping the race component when adding/modifying the original DB record if I were you Shalimar . For the adjectives you would like to record and the races you could have a list comprising the terms you want to record, off the top of my head:
Code: |
#VARIABLE KillAdjectives {troll|dwarf|palace|ceremonial}
Presuming you are triggering off of the killed message using a trigger pattern such as {^You killed the (*).} you would add this to your script before adding/updating the DB record:
#WHILE (%ismember( %word( @CapturedText, 1, " "), @KillAdjectives)=0 and %numwords( @CapturedText)!=1) {#VARIABLE CapturedText {%replace( %delnitem( %replace( @CapturedText, " ", |), 1), "|", " ")}} |
Hope this helps =) |
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4692 Location: Pensacola, FL, USA
|
Posted: Thu Jun 01, 2006 4:09 am |
Two triggers actually, but the both do the same thing:
#TRIGGER {^You killed{ the|} (*).$} {
#VAR thiskill {%1}
#IF (%iskey( @mykills, @thiskill)) {#ADDKEY mykills {@thiskill=%eval( %db( @mykills, @thiskill)+1)}} {#ADDKEY mykills {@thiskill=1}}
#VAR shortthiskill {%word( @thiskill, %numwords( @thiskill))}
#IF (%iskey( @myshortkills, @shortthiskill)) {#ADDKEY myshortkills {@shortthiskill=%eval( %db( @myshortkills, @shortthiskill)+1)}} {#ADDKEY myshortkills {@shortthiskill=1}}
}
#TRIGGER {^You mortally wound the (*), who collapses to the ground.$} {
#VAR thiskill {%1}
#IF (%iskey( @mykills, @thiskill)) {#ADDKEY mykills {@thiskill=%eval( %db( @mykills, @thiskill)+1)}} {#ADDKEY mykills {@thiskill=1}}
#VAR shortthiskill {%word( @thiskill, %numwords( @thiskill))}
#IF (%iskey( @myshortkills, @shortthiskill)) {#ADDKEY myshortkills {@shortthiskill=%eval( %db( @myshortkills, @shortthiskill)+1)}} {#ADDKEY myshortkills {@shortthiskill=1}}
}
But you are right, there are certain adjectives I would like to keep, the rest really dont matter, other then to see what all different adjectives that creature can possably have.
Also, there are some named NPC's that i would like to keep the whole name of as well, but those at least have proper capitalization of at least the first word. |
|
_________________ Discord: Shalimarwildcat |
|
|
|
Ceres Wanderer
Joined: 25 May 2006 Posts: 88
|
Posted: Thu Jun 01, 2006 1:22 pm |
If you are going to use %proper() as a test you might also want to remove nationalities beforehand otherwise you will have Ephebian/Djelian/Tsortean soldier instead of just 'soldier'. Your code could look like this if you also want to remove nationality from the adjectives:
Code: |
#VARIABLE KillAdjectives {troll|dwarf|palace|ceremonial}
#VARIABLE Nationality {Ephebian |Djelian |Tsortean |Morporkian }
Then your adapting your existing triggers:
#TRIGGER {^You killed{ the|} (*).$} {
#VAR thiskill {%1}
#FORALL Nationality {#VARIABLE thiskill {%replace(@thiskill,%i,"")}}
#WHILE (%ismember( %word( @thiskill, 1, " "), @KillAdjectives)=0 and %numwords( @thiskill)!=1 and %word( @thiskill, 1, " ")!=%proper( %word( @thiskill, 1, " "))) {#VARIABLE thiskill {%replace( %delnitem( %replace( @thiskill, " ", |), 1), "|", " ")}}
#IF (%iskey( @mykills, @thiskill)) {#ADDKEY mykills {@thiskill=%eval( %db( @mykills, @thiskill)+1)}} {#ADDKEY mykills {@thiskill=1}}
#VAR shortthiskill {%word( @thiskill, %numwords( @thiskill))}
#IF (%iskey( @myshortkills, @shortthiskill)) {#ADDKEY myshortkills {@shortthiskill=%eval(%db(@myshortkills, @shortthiskill)+1)}} {#ADDKEY myshortkills {@shortthiskill=1}}
}
#TRIGGER {^You mortally wound the (*), who collapses to the ground.$} {
#VAR thiskill {%1}
#FORALL Nationality {#VARIABLE thiskill {%replace(@thiskill,%i,"")}}
#WHILE (%ismember( %word( @thiskill, 1, " "), @KillAdjectives)=0 and %numwords( @thiskill)!=1 and %word( @thiskill, 1, " ")!=%proper( %word( @thiskill, 1, " "))) {#VARIABLE thiskill {%replace( %delnitem( %replace( @thiskill, " ", |), 1), "|", " ")}}
#IF (%iskey( @mykills, @thiskill)) {#ADDKEY mykills {@thiskill=%eval( %db( @mykills, @thiskill)+1)}} {#ADDKEY mykills {@thiskill=1}}
#VAR shortthiskill {%word( @thiskill, %numwords( @thiskill))}
#IF (%iskey( @myshortkills, @shortthiskill)) {#ADDKEY myshortkills {@shortthiskill=%eval(%db(@myshortkills, @shortthiskill)+1)}} {#ADDKEY myshortkills {@shortthiskill=1}}
} |
Note the single space after each Nationality entry.. this is to ensure proper removal of the word without leaving double spaces within the string. The script changes I have added to your existing code will also keep seperate records for all named NPCs (presuming that they are properly capitalised.
Hope this helps =) |
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4692 Location: Pensacola, FL, USA
|
Posted: Thu Jun 01, 2006 3:44 pm |
This helps immensely, thanks alot.
But the nationality i would like to keep, seeing as its more or less the same as race.
But it does rather render the old sort alias obsolete. |
|
_________________ Discord: Shalimarwildcat |
|
|
|
edb6377 Magician
Joined: 29 Nov 2005 Posts: 482
|
Posted: Fri Jun 02, 2006 7:13 pm |
to flip them around change the alias to something like this
Code: |
#ALIAS mykillssort {
#VARIABLE mykills2 %null
#VARIABLE mykills3 %null
#LOOPDB @mykills {
#MATH mykillnumword (%numwords( %key)-0)
#WHILE (@mykillnumword > 0) {
#ADD mykilltemp (" "%word( %key, @mykillnumword))
#MATH mykillnumword @mykillnumword-1
}
#ADD mykills2 %trimleft( @mykilltemp)"="%val"|"
#VARIABLE mykilltemp %null
#VARIABLE mykillnumword %null
}
#VARIABLE mykillnumword %numwords( %sort( @mykills2, 1), "|")
#WHILE (@mykillnumword > 0) {
#ADDKEY mykills3 {%word( %sort( @mykills2, 1), @mykillnumword, "|")}
#MATH mykillnumword @mykillnumword-1
}
#VARIABLE mykills2 %null
#VARIABLE mykillssorted %null
#LOOPDB @mykills3 {
#MATH mykillnumword (%numwords( %key)-0)
#WHILE (@mykillnumword > 0) {
#ADD mykilltemp (" "%word( %key, @mykillnumword))
#MATH mykillnumword @mykillnumword-1
}
#ADD mykills2 %trimleft( @mykilltemp)"="%val"|"
#VARIABLE mykilltemp %null
#VARIABLE mykillnumword %null
}
#VARIABLE mykillnumword %numwords( @mykills2, "|")
#LOOPDB @mykills2 {#ADDKEY mykillssorted {%key} %val}
#SHOWDB @mykillssorted
}
|
|
|
_________________ Confucious say "Bugs in Programs need Hammer" |
|
|
|
|
|
|
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
|
|