filter trigger problem

Post Reply
Caled
Posts: 403
Joined: Thu Apr 09, 2009 4:45 am

filter trigger problem

Post by Caled »

You are holding:
88 plain wooden vials, 58 gourd vials, 2 black iron coins, 3 whirlwind of Galleus, a suit of leather
armour, an ashen wand, 4 firefly sigils, 4 rugged, hunter's vials, a gem of transmutation, 3
ornately-carved ivory pipes, a soot-blackened tinderbox, a glob of red wax, 2 small candles, 2
vibrant sunflowers, a slender florist's box, 2 vine sigils, a white wolf vial, a tower shield, a
plain wooden pot, a diagram for a soot-blackened tinderbox, a circlet of aesthesis, an itsy-bitsy,
teeny-tiny toy violin, a fiery red tulip, a set of dig site tools, a heap of fragile, broken bones,
the skeleton of a slender, fragile humanoid, a shattered piece of pottery, a non-descript collection
of bones, a purple tulip.

You are wearing:
I coloured the lines so that it is clear there are only three lines here.

What follows, is my attempt at a filter trigger which will eventually allow me to condense the information. For now, I have merely been colouring/substituting the matches, to make it clear when my triggers are matching, and when they are not.
<string>(\d+).+vials,</string>
^ one there, is not. It should colour all matches "sea_green" but it does not. I am clearly doing something wrong, but I don't understand what. If I can get it to colour the matches sea_green, then I can change the script to:
inv.vials = inv.vials + matches[2]
replace("")

The eventual idea being to strip all common items from the inventory, leaving only the handful of "special" ones, and then to add a neat summary of my common stuff at the end of that, in a nice, easy to read format.
First though, I need to actually match lines like this:
58 gourd vials
in my filter trigger.

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE MudletPackage>
<MudletPackage version="1.0">
    <TriggerPackage>
        <TriggerGroup isActive="yes" isFolder="yes" isTempTrigger="no" isMultiline="no" isPerlSlashGOption="no" isColorizerTrigger="no" isFilterTrigger="no" isSoundTrigger="no" isColorTrigger="no" isColorTriggerFg="no" isColorTriggerBg="no">
            <name>Inventory</name>
            <script></script>
            <triggerType>0</triggerType>
            <conditonLineDelta>0</conditonLineDelta>
            <mCommand></mCommand>
            <mFgColor>#ff0000</mFgColor>
            <mBgColor>#ffff00</mBgColor>
            <mSoundFile></mSoundFile>
            <colorTriggerFgColor>#000000</colorTriggerFgColor>
            <colorTriggerBgColor>#000000</colorTriggerBgColor>
            <regexCodeList></regexCodeList>
            <regexCodePropertyList></regexCodePropertyList>
            <Trigger isActive="yes" isFolder="no" isTempTrigger="no" isMultiline="no" isPerlSlashGOption="no" isColorizerTrigger="no" isFilterTrigger="no" isSoundTrigger="no" isColorTrigger="no" isColorTriggerFg="no" isColorTriggerBg="no">
                <name>Vial Summary start</name>
                <script>inv.vials=0
selectCaptureGroup(1)
fg("yellow")
replace("My Inventory:")
resetFormat()
enableTrigger("InventoryFilter")</script>
                <triggerType>0</triggerType>
                <conditonLineDelta>1</conditonLineDelta>
                <mCommand></mCommand>
                <mFgColor>#ff0000</mFgColor>
                <mBgColor>#ffff00</mBgColor>
                <mSoundFile></mSoundFile>
                <colorTriggerFgColor>#000000</colorTriggerFgColor>
                <colorTriggerBgColor>#000000</colorTriggerBgColor>
                <regexCodeList>
                    <string>^You are holding:$</string>
                </regexCodeList>
                <regexCodePropertyList>
                    <integer>1</integer>
                </regexCodePropertyList>
            </Trigger>
            <TriggerGroup isActive="no" isFolder="yes" isTempTrigger="no" isMultiline="no" isPerlSlashGOption="no" isColorizerTrigger="no" isFilterTrigger="yes" isSoundTrigger="no" isColorTrigger="no" isColorTriggerFg="no" isColorTriggerBg="no">
                <name>InventoryFilter</name>
                <script>selectCaptureGroup(1)
fg("white")
replace(matches[1])
resetFormat()
</script>
                <triggerType>0</triggerType>
                <conditonLineDelta>0</conditonLineDelta>
                <mCommand></mCommand>
                <mFgColor>#ff0000</mFgColor>
                <mBgColor>#ffff00</mBgColor>
                <mSoundFile></mSoundFile>
                <colorTriggerFgColor>#000000</colorTriggerFgColor>
                <colorTriggerBgColor>#000000</colorTriggerBgColor>
                <regexCodeList>
                    <string>^.*,.+\.$</string>
                </regexCodeList>
                <regexCodePropertyList>
                    <integer>1</integer>
                </regexCodePropertyList>
                <Trigger isActive="yes" isFolder="no" isTempTrigger="no" isMultiline="no" isPerlSlashGOption="yes" isColorizerTrigger="no" isFilterTrigger="no" isSoundTrigger="no" isColorTrigger="no" isColorTriggerFg="no" isColorTriggerBg="no">
                    <name>Vials</name>
                    <script>selectCaptureGroup(1)
fg("sea_green")
replace(matches[1])
resetFormat()</script>
                    <triggerType>0</triggerType>
                    <conditonLineDelta>0</conditonLineDelta>
                    <mCommand></mCommand>
                    <mFgColor>#ff0000</mFgColor>
                    <mBgColor>#ffff00</mBgColor>
                    <mSoundFile></mSoundFile>
                    <colorTriggerFgColor>#000000</colorTriggerFgColor>
                    <colorTriggerBgColor>#000000</colorTriggerBgColor>
                    <regexCodeList>
                        <string>(\d+).+vials,</string>
                    </regexCodeList>
                    <regexCodePropertyList>
                        <integer>1</integer>
                    </regexCodePropertyList>
                </Trigger>
            </TriggerGroup>
            <Trigger isActive="yes" isFolder="no" isTempTrigger="no" isMultiline="no" isPerlSlashGOption="no" isColorizerTrigger="no" isFilterTrigger="no" isSoundTrigger="no" isColorTrigger="no" isColorTriggerFg="no" isColorTriggerBg="no">
                <name>Vial summary end</name>
                <script>disableTrigger("InventoryFilter")

selectCaptureGroup(1)
fg("yellow")
replace("My Clothing:")
resetFormat()</script>
                <triggerType>0</triggerType>
                <conditonLineDelta>0</conditonLineDelta>
                <mCommand></mCommand>
                <mFgColor>#ff0000</mFgColor>
                <mBgColor>#ffff00</mBgColor>
                <mSoundFile></mSoundFile>
                <colorTriggerFgColor>#000000</colorTriggerFgColor>
                <colorTriggerBgColor>#000000</colorTriggerBgColor>
                <regexCodeList>
                    <string>You are wearing:</string>
                </regexCodeList>
                <regexCodePropertyList>
                    <integer>3</integer>
                </regexCodePropertyList>
            </Trigger>
        </TriggerGroup>
    </TriggerPackage>
</MudletPackage>

Ryan
Posts: 10
Joined: Mon Jun 22, 2009 1:15 am

Re: filter trigger problem

Post by Ryan »

Filter triggers actually only pass their capture groups (matches[1]) on to their children. So you'd need to put () around the regex in your InventoryFilter trigger to get it to pass that to the children. But just set it not to be a filter trigger, because non-filtered trigger groups pass the full line on to their children whenever they match, and I think that's the functionality you ultimately want.

Also, on your Vials trigger, you need to set the regex to: (\d+).+?vials, with the added question mark. The reason is that the regex + is greedy by default, meaning it matches as much as possible. So (\d+).+vials, will match from the first number to the last "vials," on your inventory line, and that's likely to span a good chunk of your inventory. There will still be a problem with the first match, though, which will match from the first number to the first "vials," but that could be something like: "2 personal dictionaries, 3 plain wooden vials," which is not what you want. So I think the best regex is (\d+)[^,]+?vials, which prevents the second wildcard from matching a comma.

Oh, and remember that matches[] is a little different when you have the atch all option checked. Basically, it just appends all the individual matches tables from each match together, but just printTable or display it and it's pretty easy to figure out.

This is a swell idea, by the way. I'm definitely stealing it.

Ryan
Posts: 10
Joined: Mon Jun 22, 2009 1:15 am

Re: filter trigger problem

Post by Ryan »

Playing around with it a bit, I noticed a bug with selectCaptureGroup and replace that might cause you some stress. Basically, selectCaptureGroup selects by the position of the group in the line, but that position changes when you use replace on a previously captured group. Mudlet is smart enough to deal with this when it's all happening in one trigger, but if you're doing it in two separate triggers, it still breaks down. As a simple example, suppose I have a trigger that matches on the pattern "first" and replaces that with "", and a trigger that matches on the pattern "second" and colours that yellow. That works fine so long as "first" and "second" don't appear on a line together, but if they do (and "first" comes before "second", both in the line and in the order triggers are checked), the coloured part of the line will be offset from the word "second" by five characters (the length of the word first - the length of the string it was replaced with). Again, this only happens when they're in separate triggers.

Anyway, as an easy workaround, just use selectString(matches, 1) instead of selectCaptureGroup(i).

Post Reply