Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
hpoonis2010
Wanderer


Joined: 18 Jun 2019
Posts: 86

PostPosted: Thu May 14, 2020 3:35 pm   

Pattern Matching
 
So, after a period (very short) of a day or so where this was working...now it is not. At least not for all cases.

Aardwolf mud cannot just relay information, it has to be fancied up and dandied about. Thus, if one identifies an item, in all cases it looks like:-

Code:

[5749/5749hp 3789/3857mn 4598/4598mv 22qt 654tnl] > app 1
You appraise the true value of a mysterious black pill.

+-----------------------------------------------------------------+
| Keywords   : black pill 201heal                                 |
| Name       : a mysterious black pill                            |
| Id         : 2263817161                                         |
| Type       : Pill                      Level  :   201           |
| Worth      : 3,216                     Weight :    13           |
| Score      : 0                                                  |
| Material   : aether                                             |
| Flags      : unique, glow, hum, magic, nolocate, V3             |
| Clan Item  : From The Order of Shadokil                         |
+-----------------------------------------------------------------+
| Spells     : 1 use of level 201 'heal'                          |
|            : 1 use of level 201 'heal'                          |
|            : 1 use of level 201 'heal'                          |
|            : 1 use of level 201 'heal'                          |
+-----------------------------------------------------------------+

[5749/5749hp 3789/3857mn 4598/4598mv 22qt 654tnl] >


It is becoming a headache beyond measure to try and get this information into a @var. If I use %a then I do not get strings that begin with non-alpha (or digits) characters. If I ignore any cmud string pattern (%w, %a, etc) and just use &{var.field} then I also get the chaff on the end of each line of data.

Eg., item names can be:-

Code:
a golden =^~cat~^= mask
==Seeko's=Dog=Collar==
[[>]>adamantite bracer<[<]]


Which wreaks havoc with cmud's tasty character list. Far from easy.

The particular items, and thus, the number of 'sections' of this layout is dependent on the type of item,]. So armor, potions, containers, etc have different labels for the various stats.

Also, trying to match 4 lines for spells to go into a &item.spell space is another headache and I have just been letting that slip for the time being but I have tried wrapping my head around trigger conditions and trigger states and all I end up doing is creating cmud exceptions that cause the software to shit itself.

...and lastly (and I am guestimating this as I tried so many permutations of characters that the original working effort went across the Styx aeons ago), the trigger I had to end the capture

Code:
+$\n\n\[


decided it would no longer play the game and I have spun myself around trying to get to the end of the thing. A simple 'newline' does not exist. I tried flicking the regex check and using \n and this was what was working for the day or so but, once that ceased, I went back to cmud patterns and nothing seems to want to work with anything like

Code:
+-----------------------------------------------------------------+

[


As you can see, the repetition of the ascii-char line (+--etc--+) throught out the item info does nothing to make this a simple affair.

So, if any (in particular) regex wizards have their HR Pufnstuf hats on, I'd appreciate a nod toward figuring this mess out.
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4156
Location: Pensacola, FL, USA

PostPosted: Thu May 14, 2020 9:08 pm   
 
CMUD fires on the +----+ line just fine, you may have just miscounted your dashes, to make this easy, look at the pattern tab of your trigger.

In the end, you are likely going to want a state-based trigger:

#TR {+-----------------------------------------------------------------+} {}
#COND {| Keywords %s: (*)%s|} {$keywords=%replace(%trim(%1), " ", "|")} {within|param=1}
#COND {| Name %s: (*)%s|} {$name=%trim(%1)} {within|param=1}
#COND {| ID %s: (%d)%s|} {} {within|param=1}
#COND {| Type %s: (*)%s Level %s: (%d)%s|} {} {within|param=1}

And so on
_________________
Discord: Shalimar#3679
Reply with quote
hpoonis2010
Wanderer


Joined: 18 Jun 2019
Posts: 86

PostPosted: Fri May 15, 2020 7:41 am   
 
For the regex I never had a 'count' as such, I just used

^\+[-]\+$\n\n

Which I would have expected to collect the line beginning with a '+' and ending with '+' followed by two cr.

In your instance, of course, I only really need to search for {^+---} as that should always begin the trigger string, whereas {---+} will always end it.

Now this was what I was thinking of but, after looking at it all day (while being distracted by work and other things) my head was spinning.

However, as usual, you are the goto guy/gal/entity of your choosing.

But, can you clarify...

As I said, there are more keywords, and thus more/different 'sections' that appear depending on the item type. How does the 'within' clause help here? Are these looking within 1 line of the initial trigger (+---etc) ? If so they will not be valid as you can see from the example I posted, some keywords are 6-9 lines away from the initial +--- line. Or is it 'within' 1 line of the condition trigger?

...and terminating the capture, when the item id also ends with the same string it began on...and my trials at trying to grasp that line with a blank line under it went around in circles. There appears to be NO actual 'newline' pattern, as regex has...or most other general programming langauges for that matter.

I see you used local vars. Could I not still use the db var type (&var.field) instead?

If so, and given that some keywords always appear on the same line as others, would it be also valid to use:

Eg.,

#COND {| Keywords %s: &{Item.keywords}%s|} {$keywords=%replace(%trim(&Item.keywords), " ", "|")} {within|param=1}

and

#COND {| Type %s: &{Item.type}%s Level %s: &{item.level}%s|} {} {within|param=1}
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4156
Location: Pensacola, FL, USA

PostPosted: Fri May 15, 2020 11:32 am   
 
I am not so good with raw REGEX, never needed to be as zscript patterns get converted to regex behind the scenes.

And I was unaware that some of the categories were optional. I assumed you were showing the default pattern for everything.
You are correct that the within is not relevant under these circumstances.
Local vars will not be the most efficient as a result.

Instead, you will need a separate trigger for each potential like of data.

Also, there is no point in defining the variable in the pattern (which can be fun) if you need to alter the data in the body of the script.
There is also the point that the keywords are showing up before we know what item in the database is being referenced.

#TR {| Keywords %s: (*) %s|} {keywords=%replace(%trim(%1), " ", "|")}

Code:
#TR {| Name %s: (*)%s|} {
  itemName=%trim(%1)
  item=%db(@masterDB, @itemName)
  #ADDKEY item Keywords @keywords
  }


This SHOULD now work:

#TR {| Type %s: &{Item.type}%s Level %s: &{item.level}%s|} {}

If not use:

Code:
#TR {| Type %s: (*)%s Level %s: (%d)%s|} {
  #ADDKEY item Type %1
  #ADDKEY item Level %2
  }
_________________
Discord: Shalimar#3679
Reply with quote
hpoonis2010
Wanderer


Joined: 18 Jun 2019
Posts: 86

PostPosted: Fri May 15, 2020 3:24 pm   
 
With your idea of the #CONDITION, would this work for the spells; spells vary from 1 line to (as far as I know) a maximum of 5 lines?

TRIGGER {Spells}. reparse the same line for ':' for the first spell (and if only one, all the good)

then

COND the next (max) 4 lines to trigger on ':' also.
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4156
Location: Pensacola, FL, USA

PostPosted: Fri May 15, 2020 11:55 pm   
 
Yes, that was why I started down that avenue, the spells would still need to be a condition.

Code:
#TR {| Spells %s: (%d) use of level %d '(*)'%s|} {
  spells=%db(@item, "Spells")
  #ADDKEY spells %2 (%db(@spells, %2)+%1)
  }
#COND {*} {#IF (%line!="+-----------------------------------------------------------------+") {
  #STATE 1
  #CALL %match(%line, "(%d) use of level %d '(*)'", $count, $spell)
  #ADDKEY spells $spell (%db(@spells, $spell)+$count)
  } {#ADDKEY item Spells @spells}} {withinparam=1}
_________________
Discord: Shalimar#3679
Reply with quote
hpoonis2010
Wanderer


Joined: 18 Jun 2019
Posts: 86

PostPosted: Sun May 17, 2020 12:26 am   
 
AH. Well, most of your help worked. However, the spells thing failed when it came up against:

Code:
You appraise the true value of Assassins' Brew.

+-----------------------------------------------------------------+
| Keywords   : brew protection sk55260                            |
| Name       : Assassins' Brew                                    |
| Id         : 2263817156                                         |
| Type       : Potion                    Level  :    26           |
| Worth      : 416                       Weight :    13           |
| Score      : 0                                                  |
| Material   : energy                                             |
| Flags      : glow, hum, magic, burn-proof, nolocate, V3, static |
| Clan Item  : From The Order of Shadokil                         |
+-----------------------------------------------------------------+
| Spells     : 1 use of level 26 'protection good'                |
|            : 1 use of level 26 'inertial barrier'               |
|            : 1 use of level 26 'adrenaline control'             |
|            : 1 use of level 26 'levitation'                     |
+-----------------------------------------------------------------+

[7770/7770hp 5321/5321mn 5398/5398mv 0qt 1339tnl] >


Given that there is a 'memo' field for the database, I am more than happy to use that and was hoping for an output of

line1
line2
line 3
line 4
...

If not, a regular text field with '|' separators.

So I tried...

Code:
#TR {~| Spells%s: (*)~|}{#VAR tempspells %trim(%1)}


because I wanted the entire line of useful text. Then,

Code:
#COND { : (*)~|} {#CALL %additem(%trim(%1), @tempspells)}
#COND {^+[-]+$} {#STATE 1;#ADDKEY item spells @tempspells }


This fails almost completely with item.spells being populated with:


Code:
brew protection sk55260                          |1 use of level 26 'protection good'              |brew protection sk55260|1 use of level 26 'protection good'|brew protection sk55260|1 use of level 26 'protection good'|brew protection sk55260|1 use of level 26 'protection good'|brew protection sk55260|1 use of level 26 'protection good'


...and I have no idea how I got that, and without %trim stripping the spaces...but it is 2.20am and I have had a nice day of Czech/Slovak beer and sunny bike riding.
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4156
Location: Pensacola, FL, USA

PostPosted: Sun May 17, 2020 3:06 am   
 
%additem only returns a value, you still have to assign that value back to the variable

You also have your state trigger set up so it never resets all the way, your final line always sets it back to the middle, so your variable is never getting reset either.

Try this:

#TR {~| Spells%s: (*)~|}{#VAR tempspells %trim(%1)}
#COND { : (*)~|} {tempspells=%additem(%trim(%1), @tempspells);#STATE 1} {within|param=1}
#COND {*} {#ADDKEY item spells @tempspells }
_________________
Discord: Shalimar#3679
Reply with quote
hpoonis2010
Wanderer


Joined: 18 Jun 2019
Posts: 86

PostPosted: Sun May 17, 2020 7:15 am   
 
I was thinking (after waking up with this in my head), wouldn't it work that I can use?

#TR {~| Spells%s: (*)~|}{#VAR tempspells %trim(%1);#TEMP {+------}{#ADDKEY Item spells @tempspells;#ADDNEW All @Item }}
#COND { : (*)~|} {tempspells=%additem(%trim(%1), @tempspells);#STATE 1} {within|param=1}

Either way, the initial, first state trigger is not firing. The temspells variable is being populated but the KEY is not being added to the item record.
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4156
Location: Pensacola, FL, USA

PostPosted: Sun May 17, 2020 1:12 pm   
 
You need a space between your closing and opening brackets } { in the #TEMP

#ADDNEW is not a recognized command.
_________________
Discord: Shalimar#3679
Reply with quote
hpoonis2010
Wanderer


Joined: 18 Jun 2019
Posts: 86

PostPosted: Sun May 17, 2020 2:02 pm   
 
There is a space. I didn't use that code.

Here is the current situation.

#TR {~| Spells%s: (*)~|} {#VAR tempspells "";#VAR tempspells %trim(%1)} //because, for some reason, #VAR is not clearing tempspells between item ident uses.
#COND "speltrig" {~|%s: (*)~|} {tempspells=%additem(%trim(%1), @tempspells);#STATE 1;#TEMP {+-----} {#ADDKEY item spells @tempspells;#STATE speltrig 0}}

Gives me a perfect db record.

room=1473|zone=Shadokil|keywords=whispers death sk55215 sk15 curse|name=whispers of death|id=2263817157|type=Scroll|level=200|worth=3200|weight=13|wearable=hold|score=0|material=light|flags=unique, glow, hum, magic, burn-proof, nolocate, V3|spells="1 use of level 200 'curse'|1 use of level 200 'curse'|1 use of level 200 'curse'|1 use of level 200 'curse'"


HOWEVER, my item ident functions begin with

#T+ eqident // EqIdent has an ENABLE script which opens the dbfile enables all the ident triggers to function

The DISABLE script will write @item to the DB file 'equip'. However, no amount of muddling about can get this to work. If I add #T- eqident to the #TEMP trigger

#TEMP {+-----} {#ADDKEY item spells @tempspells;#STATE speltrig 0;#T- eqident}

then @item does not get the spells. If I put the #T- command outside temp trigger as the last command of the #COND then I only get two spell lines out of 4.
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4156
Location: Pensacola, FL, USA

PostPosted: Sun May 17, 2020 7:03 pm   
 
Maybe just change up the order of things inside the temp?
There is also no need for the STATE 0, that is why the condition is of type within, after x lines without a match it automatically progresses.
The ID should also be on the main trigger if it is going to have one, not on a given state

#TR "spellTrig" {~| Spells%s: (*)~|} {#VAR tempspells "";#VAR tempspells %trim(%1)}
#COND {~|%s: (*)~|} {tempspells=%additem(%trim(%1), @tempspells);#STATE 1;#TEMP {+-----} {#t- equident;#ADDKEY item spells @tempspells}} {within|param=1}
_________________
Discord: Shalimar#3679
Reply with quote
hpoonis2010
Wanderer


Joined: 18 Jun 2019
Posts: 86

PostPosted: Mon May 18, 2020 6:48 am   
 
Mkay...moving the state back to the parent worked. I moved it originally as the original code you suggested wasn't right also.

So...TEMP trigger is up at parent. #T- now works also, $tempspells is populated and @item seems to be complete also.

Thanks for all your assist. As usual, a great help.

Now I may try to figure out a way to loop everything under eqident for multiple items. :D But at least I can now populate the database.
Reply with quote
hpoonis2010
Wanderer


Joined: 18 Jun 2019
Posts: 86

PostPosted: Mon May 18, 2020 9:18 am   
 
Bugger!

There are logic problems again. It all comes back to the format. Consider:-

Code:
+-----------------------------------------------------------------+
| Keywords   : black armor polished                               |
| Name       : (Polished) Black Armor                             |
| Id         : 2290058091                                         |
| Type       : Armor                     Level  :   201           |
| Worth      : 17,500                    Weight :    10           |
| Wearable   : body                                               |
| Score      : 320                                                |
| Material   : titanium                                           |
| Flags      : unique, invis, magic, V3                           |
| Notes      : Expires in 1 hour, 19 minutes and 3 seconds.       |
+-----------------------------------------------------------------+
| Stat Mods  : Hit roll     : +24      Damage roll  : +26         |
|              Intelligence : +4       Dexterity    : +2          |
|              Hit points   : +40      Mana         : +40         |
+-----------------------------------------------------------------+
| Resist Mods: All physical : +11      All magic    : +8          |
|              Bash         : +10      Air          : +10         |
|              Energy       : +10                                 |
+-----------------------------------------------------------------+

[675/675hp 181/517mn 890/890mv 0qt 3651tnl] >

+-----------------------------------------------------------------+
| Keywords   : patched red traveling cloak vibrant                |
| Name       : (Vibrant) a patched red traveling cloak            |
| Id         : 2290055584                                         |
| Type       : Armor                     Level  :   200           |
| Worth      : 37,185                    Weight :    21           |
| Wearable   : back                                               |
| Score      : 415                                                |
| Material   : cotton                                             |
| Flags      : unique, magic, V3                                  |
| Notes      : Expires in 25 minutes and 56 seconds.              |
+-----------------------------------------------------------------+
| Stat Mods  : Wisdom       : +3       Dexterity    : +5          |
|              Intelligence : +2       Constitution : +12         |
|              Luck         : +2       Hit points   : +20         |
|              Mana         : +20      Moves        : +40         |
|              Hit roll     : +10      Damage roll  : +20         |
+-----------------------------------------------------------------+
| Resist Mods: Light        : +20                                 |
+-----------------------------------------------------------------+

[675/675hp 116/517mn 890/890mv 0qt 3651tnl] >

+-----------------------------------------------------------------+
| Keywords   : algain adamantite sword long polished              |
| Name       : (Polished) Algain Adamantite Long Sword            |
| Id         : 2290080930                                         |
| Type       : Weapon                    Level  :    90           |
| Worth      : 2,250                     Weight :    11           |
| Wearable   : wield                                              |
| Score      : 778                                                |
| Material   : adamantium                                         |
| Flags      : unique, glow, hum, V3                              |
| Notes      : Expires in 41 minutes and 38 seconds.              |
+-----------------------------------------------------------------+
| Weapon Type: sword                  Average Dam :    175        |
| Inflicts   : cleave                 Damage Type : Slash         |
| Specials   : sharp                                              |
+-----------------------------------------------------------------+
| Stat Mods  : Strength     : -1       Constitution : -2          |
|              Hit roll     : +10      Wisdom       : +2          |
|              Mana         : +20      Moves        : +20         |
|              Damage roll  : +8                                  |
+-----------------------------------------------------------------+

[675/675hp 46/517mn 890/890mv 0qt 3651tnl] >


The number of lines and keywords varies greatly. The only option was to parse for

---+(newline)(blank line) to guarantee that the end of the item has definitely been achieved.

So, slightly altering existing triggers and adding, etc.

I now have triggers collecting everything and a definite test/check .

#TR {------+|(*) does not have that item for sale} {}
#COND {^$} {#T- EqIdent} {within|praram=1}

and thus far it seems to be working out well. I have tested against a bunch of items and @item is being fully populated.

I thought about trying to trigger the sections as each seems to have a patterned start (Weapon Type, Stat Mods, Resist Mods, Spells, Skill Mods, etc) but that would require a reparse of that same line as the following keywords are also slightly variable (All magic, Hide, Slash, etc) for each section.

But, it apparently now works. Oh for the simple life!
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4156
Location: Pensacola, FL, USA

PostPosted: Mon May 18, 2020 11:27 am   
 
#TR {-----+$$} {} //should test for a blank following line
_________________
Discord: Shalimar#3679
Reply with quote
hpoonis2010
Wanderer


Joined: 18 Jun 2019
Posts: 86

PostPosted: Mon May 18, 2020 12:23 pm   
 
That is also a problem but I have it covered with...

{-----+|(*) not have that item for sale|A full appraisal will reveal}

...and can update that with whatever else the MUD server cares to pitch out.

Now I have to figure out the simple way to either discard an existing record or update an existing record with new data.

Probably SQL.
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
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

© 2009 Zugg Software. Hosted by Wolfpaw.net