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
oldguy2
Wizard


Joined: 17 Jun 2006
Posts: 1201

PostPosted: Fri Feb 22, 2008 10:58 pm   

Need Help With Complicated Multi-line Trigger
 
Alright I need help figuring this out for Cmud. I searched through the forum and found an example of what I am talking about.

http://forums.zuggsoft.com/forums/viewtopic.php?t=14684&start=0&postdays=0&postorder=asc&highlight=batches+of

I want to capture the amount and type of plant and store them in a data record and total them as it runs through each pouch. However, this original post didn't consider multiple lines.

The original post example:

pouch #12 has 12 batches of wirren, 2 batches of harfy, 5 batches of wirren.

First off that is not even correct, but that really doesn't matter. The problem is this line varies in length.

Example of output:

Pouch #1234 contains 26 batches of Sata, 36 batches of Megillos, 48 batches of Arkasu, 46 batches of Malloran, 56 batches of Kural, 10 batches of Denallo.
Pouch #5678 contains 8 batches of Siriena, 4 batches of Kelventari, 35 batches of Courgia, 66 batches of Witan, 5 batches of Yavin, 29 batches of Vaxvarna.
Pouch #9101 contains 3 batches of Mar, 17 batches of Bukandas, 3 batches of Zaganzar, 4 batches of Quarri, 11 batches of Harfy, 40 batches of Nann.
Pouch #1121 contains 5 batches of Adelsh, 30 batches of Alethe, 3 batches of Darsurion, 163 batches of Atigax, 49 batches of Shirolos, 16 batches of Phoroz.
530h, 530m de-

What I want to do is capture the amount of each herb/poison and add that to a database keeping a total. Then instead of this confusing output I will print something like (but not exactly) the following back to the screen:

Pouch1:

26 Sata, 36 Megillos, 48 Arkasu, 46 Malloran, 56 Kural, 10 Denallo

Pouch2:

8 Siriena, 4 Kelventari, 35 Courgia, 66 Witan, 5 Yavin, 29 Vaxvarna

Plant Totals:

50 Sata, 60 Megillos, 80 Arkasu...and so on.


As you can see the line wraps at a random spot on the end depending on the length of the plant names. Some pouches may only have 1 item and others may have 6. I can't figure out how to do this and capture everything due to this crappy output and random wrapping at the end. Anyone able to help me out here?
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Fri Feb 22, 2008 11:29 pm   
 
What needs to be done to capture this is very different if it is server side wrapping or client side wrapping. You seem to be indicating that server side wrapping is involved, and the first thing I would suggest is trying to find a way to turn it off. Once that wrapping is turned off CMud will take over for the line wrapping and triggering will be easy.

Either way it is doable, just let us know what the actual wrapping state is so we can write the captures.
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
oldguy2
Wizard


Joined: 17 Jun 2006
Posts: 1201

PostPosted: Sat Feb 23, 2008 12:50 am   
 
Ah well that is a problem too. It's server side. You can change width but only up to 200. It won't let you do anything larger. Currently I have it set to 150 since I have a 19" screen. So that wrapping you see is with 150 width.

This mud is Avalon. The help file states:

If your screen width is not exactly 80 characters, you may find Avalon wraps lines too soon or too
late. This can be corrected by use of the WIDTH command. Simply type WIDTH followed by the
numbers of characters that can fit on one line of your display. The default is 80.

This is an example of output at 80:

Pouch #1234 contains 10 batches of Kaskamak, 161 batches of Mandrake, 1 batches of Etarka, 28
batches of Lestagii, 42 batches of Athillias, 83 batches of Karfar.
Pouch #5678 contains 77 batches of Kathkusa, 2 batches of Breldiar, 11 batches of Athanzar, 9
batches of Surnamen, 25 batches of Jitsu, 36 batches of Acaana.
Pouch #9101 contains 75 batches of Quirrog, 2 batches of Exaar, 152 batches of Yake, 79 batches of
Grelixar, 41 batches of Mouurark, 141 batches of Wyg.
Pouch #1121 contains 3 batches of Furglewort, 35 batches of Tyrlar, 65 batches of Ajkara, 1
batches of Jegga, 12 batches of Akmar, 9 batches of Blackroot.
Pouch #3141 contains 26 batches of Sata, 39 batches of Megillos, 50 batches of Arkasu, 53 batches
of Malloran, 56 batches of Kural, 16 batches of Denallo.

Of course I hate 80 output because I end up with everything in the left half of the screen. So I set it to 150, anything above that or inbetween seems to cause all kinds of jagged lines like this:

South of Cassiandora square.
The sky about you is alive with the day-time. You stand surveying your surroundings at the southern quarter of the Cassiandora square. Westwards and
Eastwards the square meets its corners and a number of shop-fronts claim a portion of your attention, their brightly painted signs flapping in the
breeze. To the north the square is home to the Mercinaen market, flamboyant awnings of colourful cloth beg the passer-by to grace the stall owner
with their presence. To the south the square narrows into a wide road which delves deeper into the slacker-paced sections of the city. A warm
breeze wafts over you and the heavens above are devoid of cloud.
Reply with quote
oldguy2
Wizard


Joined: 17 Jun 2006
Posts: 1201

PostPosted: Sat Feb 23, 2008 1:13 am   
 
Actually I just looked at my log...that room description above is from the log is at 150 width...It didn't look like that on the screen though. Now I am not sure what to set it at.
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Sat Feb 23, 2008 2:15 am   
 
Different fonts have different widths, and the size also changes. I am sure the appearance is vastly different betweent the forums and your screen because of both of those factors. Knowing that it is server side wrapping is really the most important thing to make a proper trigger for this.

In order to do the requested totaling I will also need to know something that occurs before and and after the pouch displays. For instance a command that initiates the display and line that indicates the end. If multiple commands are required to display the contents of the pouches then I would need details on how to fabricate those commands. If there is no specifc end message then perhaps it is possible to fabricate one of those through an invalid command, and I would need some details on that.

If you can supply me those details soon then I should have some time to write the whole thing up. Otherwise it will wait till morning.
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
oldguy2
Wizard


Joined: 17 Jun 2006
Posts: 1201

PostPosted: Sat Feb 23, 2008 3:07 am   
 
Command is pouchlist.

The end is the prompt as I show in that first post.
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Sun Feb 24, 2008 12:59 am   
 
I am sorry it took me so long to get back to this. I was having a rather good programming day and have finally gotten the project I was focused on close enough to a production status that I can do this. I will write it up now.
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
oldguy2
Wizard


Joined: 17 Jun 2006
Posts: 1201

PostPosted: Sun Feb 24, 2008 10:25 pm   
 
No worries.
Reply with quote
oldguy2
Wizard


Joined: 17 Jun 2006
Posts: 1201

PostPosted: Sat Mar 01, 2008 2:26 am   
 
Anyone figure this one out?
Reply with quote
oldguy2
Wizard


Joined: 17 Jun 2006
Posts: 1201

PostPosted: Fri Mar 14, 2008 8:48 pm   
 
Sorry to bump this, but no one ever got back to me yet.
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Fri Mar 14, 2008 10:34 pm   
 
The original parsing %subregex I set up to do this killed CMud2.18. Since subregex is getting upgraded in the next beta I am just going to wait till then and do this with my normal beta testing. MY apologies for not saying something sooner.
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Sun May 04, 2008 1:04 am   
 
Giving this a bump now so I don't have to hunt for it on my first cup of coffee tommorrow. It just made top of my list.
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Sun May 04, 2008 11:38 am   
 
I think I got this about nailed. I didn't include gagging and redisplay, but all the data is neatly captured into 2 variables. It uses some of the new beta %subregex things, and also helped to point out a few bugs in that code for me.
Code:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
  <class name="PouchCap" copy="yes">
    <trigger name="pouchlist" type="Command Input" priority="1" stop="true" copy="yes">
      <pattern>^pouchlist$</pattern>
      <trigger param="50" regex="true">
        <pattern>^Pouch #\d+</pattern>
        <value>Pouches=%line</value>
      </trigger>
      <trigger type="Loop Lines" param="50" regex="true" prompt="true">
        <value>#IF (%regex(%line,"^\d+h, \d+m")) {
 #STATE PouchList 0
 Pouches=%subregex(@Pouches,"Pouch #(\d+) contains |(\d+) batches of (\w+)|(\.)","(?(1)\'1'=|(?(4)\||\2 \3))(?($)\((?LIST:3:$)-(?LIST:2:$)\))")
 $i=%numitems(@Pouches)
 $Herbs=%stripq(%item(@Pouches,$i))
 #DELNITEM Pouches $i
 $Counts=%word($Herbs,2,"-")
 $Herbs=%word($Herbs,1,"-")
 $i=1
 HerbTotals=""
 #FORALL $Herbs {
  #IF (%i) {#ADDKEY HerbTotals {%i} {%eval(%db(@HerbTotals,%i)+%item($Counts,$i))}}
  $i=$i+1
 }
} {
 Pouches=%concat(@Pouches," ",%line)
}</value>
      </trigger>
    </trigger>
    <var name="Pouches" usedef="true" copy="yes"/>
    <var name="HerbTotals" type="Record" usedef="true" copy="yes"/>
  </class>
</cmud>
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
oldguy2
Wizard


Joined: 17 Jun 2006
Posts: 1201

PostPosted: Sun May 04, 2008 12:31 pm   
 
Again excellent job. Glad it helped you work on the bugs too!
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