|
StackAdder Wanderer
Joined: 30 Sep 2003 Posts: 77 Location: United Kingdom
|
Posted: Sat Oct 04, 2003 4:44 am
Query re pattern wild cards |
I may be being dense here, so apologies if that is the case.
I have a pattern of ^(%w)(%s)(%w)(%p)
which I intended to match on data from a who output:
55853 exp <45hp 125m 66mv> who
--------------------------------------------------------------------------------
Mortal Mandel the mortal
Mortal Rayan the mortal
Warrior Fatale, always happy... never satisfied... ** THORN **
Mortal Deign the mortal
Mortal Maniaxe the mortal
Avatar Zuggy. >>coming soon...<<
Mortal Fer Ferentzy.
Fighter Randwar. [] Bad Puppy! []
Fighter Gomez' * Warrior of Jesus *
--------------------------------------------------------------------------------
There are 9 visible players.
There is a total of 11 players connected.
--------------------------------------------------------------------------------
(accepting the fact that I planned to do some bits and pieces to enable/disable various triggers so it only looked at the chars & not the rest of the gumph)
I was surprised to find that %p matches spaces as well as punctuation, but actually that is useful in this case.
I was surprised to find that the matched portions of the above character lines were (ignoring the simple cases):
"Warrior Fatale, always happy... never satisfied... ** "
"Avatar Zuggy. >>coming soon...<<"
"Fighter Randwar. [] Bad Puppy! []"
(and Gomez wasn't matched at all)
Causes for surprise:
Shouldn't "Warrior Fatale, " be the extent of the match?
... "always" is not punctuation, so the pattern should stop there?
Why does it then stop after "** "?
(I guess Zuggy and Randwar are subsets of those issues) (Zuggy? Wanna tell me anything Zugg!)
Gomez' - is ' not punctuation? " is, so this was a surprise.
Of course, what I really wanted was the pattern without the (%p),so it isn't much of a problem, but I would like to understand the behaviour better.
[edit] I have since been looking at the {^string} construct.
{^doll} matches dollsuffix but not prefixdoll - I would have thought that it would match neither or both...
It would be useful on occasion to be able to match
(wildcard)(not wildcard)
eg (%w)(^%p) - for matching a word which isn't followed by punctuation, which I guess I can do with a regexp but then I can't capture it... |
|
|
|
LightBulb MASTER
Joined: 28 Nov 2000 Posts: 4817 Location: USA
|
Posted: Sat Oct 04, 2003 6:26 pm |
Very odd. I made a trigger of my own, using your pattern. I skipped %2 since it should always produce a blank line.
#TR {^(%w)(%s)(%w)(%p)} {#SAY {%1};#SAY %3;#SAY {%4}}
I pasted in the wholist sample, with parsing disable, and got these results (input in red, output from #SAY in blue), skipping the simple cases:
Warrior Fatale, always happy... never satisfied... ** THORN **
Warrior
Fatale
,
Avatar Zuggy. >>coming soon...<<
Avatar
Zuggy
. >>
Mortal Fer Ferentzy.
Mortal
Fer
Fighter Randwar. [] Bad Puppy! []
Fighter
Randwar
. []
Fighter Gomez' * Warrior of Jesus *
As you can see, %4 does indeed stop matching after , > and ] (and any trailing spaces). It would probably match the . after Ferentzy except that Ferentzy is the third word, not the second.
^ marks the beginning of a line, so ^doll matches any line which begins with doll, including dollsuffix but not prefixdoll.
To match the first two words in the line, just use
^(%w) (%w) |
|
|
|
StackAdder Wanderer
Joined: 30 Sep 2003 Posts: 77 Location: United Kingdom
|
Posted: Sat Oct 04, 2003 8:51 pm |
Getting weirder... I now have:
#var wname %3
#gag
#var dbrec %find( %3, ,Name)
#var tname %3
#var tstat %1
#echo -> %3 / %1 : %db( @dbrec, Clan)
#if (@dbrec=="") {#if (%3 != is & %3 !=are) {
#echo ->hi
#new player {Name=@tname|Status=@tstat|Alignment=Evil|Clan=Human}
#echo ->lo
} {#noop}} {#noop}
I have to assign default values to alignment and clan cos I have made them single option thingies, and it doesnt store them without.
Now I have a lil show and tell alias which produces the test data :
#show [55853 exp] ~<45hp 125m 66mv> who
#show --------------------------------------------------------------------------------
#show Mortal Mandel the mortal
#show Mortal Rayan the mortal
#show Warrior Fatale, always happy... never satisfied... ** THORN **
#show Mortal Deign the mortal
#show Mortal Maniaxe the mortal
#show Avatar Zuggy. >>coming soon...~<~<
#show Mortal Fer Ferentzy.
#show Fighter Randwar. ~[~] Bad Puppy~! ~[~]
#show Fighter Gomez' * Warrior of Jesus *
#show --------------------------------------------------------------------------------
#show There are 9 visible players.
#show There is a total of 11 players connected.
#show --------------------------------------------------------------------------------
#show ""
#show ~[55853 exp~] ~<45hp 125m 66mv~> finger fatale
This is not quite the same as the mud outputs as that is tabbed between status (%1) and name (%3) If I don't have a pattern for the spaces it doesn't work at all, and I am kinda keeping it as (%s) instead of just %s cos that is how I am...
Now, I have a trigger on
^(%w)(%s)(%w)
with a script of
#var wname %3
#gag
#var dbrec %find( %3, ,Name)
#var tname %3
#var tstat %1
#echo -> %3 / %1 : %db( @dbrec, Clan)
#if (@dbrec=="") {#if (%3 != is & %3 !=are) {
#echo ->hi
#new player {Name=@tname|Status=@tstat|Alignment=Evil|Clan=Human}
#echo ->lo
} {#noop}} {#noop}
Now this works and populates the databse offline. Online it doesn't (which kind of implies it is a problem with %s not matching the spaces in the mud output)
Also odd (I think) is that if I put the #gag and #echo lines after the #if (@dbrec... one they never fire, though as far as I can see the IF has all the requisite nops to make it work...
Also a problem is that frequently when going into the script editor, the #IF (@dbrec line gets a spare "dbrec)" on the end of the line which is annoying, but fixable (would be nice if it got fixed though Zugg!)
And I have used your exact version from above Lightbulb, and it works fine - dunno what I was doin wrong with that before. ' not being punctuation still confusing tho! |
|
|
|
LightBulb MASTER
Joined: 28 Nov 2000 Posts: 4817 Location: USA
|
Posted: Sat Oct 04, 2003 11:59 pm |
%find isn't the best choice, since it will match any record whose Name column contains the string being searched for. That is, if you have Dracula in your database and a new player named Acul shows up, it will match the existing record for Dracula. And if you have both Acul and Dracula in the database, Acul will match both records and give you a string-list with both record numbers. You need an exact match, so you should use %query.
This is for command-line entry.
#AL who {#T+ who1;~who}
#TR who1 {^(%w)%s(%w)} {
#GAG
#VAR dbrec %query( &Name = "%2")
#VAR tname %2
#VAR tstat %1
#ECHO -> %2 / %1 : %db( @dbrec, Clan)
#IF (%2 = "is" OR %2 = "are") {
#UNGAG
#T- who1
} {
#IF (@dbrec = "") {
#ECHO ->hi
#NEW player {Name=@tname|Status=@tstat|Alignment=Evil|Clan=Human}
#ECHO ->lo
}
}
} {} {disable}
I agree on ', I would have thought it was punctuation too. |
|
|
|
StackAdder Wanderer
Joined: 30 Sep 2003 Posts: 77 Location: United Kingdom
|
Posted: Sun Oct 05, 2003 1:45 pm |
OK that is great. Oh and can I say that I think you are very good at explaining the reasons behind your suggestions.
One of the problems I had was that I hadn't realised the databse window needs to be open in order for the #new to work (I have tested with #dbonline and #dboffline and effect is the same, window closed, no updates, window open, updates OK)
Having discovered this, the single option fields don't need to have a default value put in , so I can just update the bits which I have information for, which is cool.
Now to try and squeeze the other data I want in :)
Cheers LB |
|
|
|
|
|
|
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
|
|