|
michael013 Newbie
Joined: 10 Mar 2003 Posts: 3 Location: Canada
|
Posted: Mon Mar 10, 2003 2:16 pm
trigger problem with multiline matching |
Hello.
Sorry for posting into the wrong thread earlier. *blush*
I have read these forums all day now and still havent got my trigger to work. so i decided to make a topic here. I am new to
this so if you know the answer, please write
it that a newbie would understand.
Basicly the question is:
How can i make a trigger that matches "from the end of a new line until to the first white space"
if the new line contains the words eg.
"a strip of dried meat" - it would match the word "meat" and only "meat" !!
or - a item "a black metal shield" - would match a word "shield".
"a saddlecloth" would then result - "saddlecloth". I hope you get what i mean.
The trick really is that some items in inventory consist of "a" then whitespace and then 1 - 3 words. I would really like to match only the final word of the item - now how should i write this ?
Thank You in advance. |
|
|
|
Kjata GURU
Joined: 10 Oct 2000 Posts: 4379 Location: USA
|
Posted: Mon Mar 10, 2003 2:24 pm |
The trick here is to combine the use of the %w wildcard (which matches only one word) and the $ pattern expression which tells zMUD to match the end of a line. In this case, you would have this trigger:
#TRIGGER {(%w)$} {#VAR lastword {%1}}
Here, the %w will not match anything else except the last word of the line because it is followed by a $ which forces zMUD to look for a newline right after the word in question.
Since the %w is surrounded by parenthesis, whatever text it matched is available using %1 (because it is the first wildcard surrounded by parenthesis in the pattern). The trigger then proceeds to save this in the @lastword variable.
Just in case, the trigger was given in a format that allows you to just copy and paste it into the command line and press Enter to create it. This would be equivalent to enter it in the Settings Editor yourself where the Pattern and Value appear in the command above in this form:
#TRIGGER {pattern} {value}
Kjata |
|
|
|
michael013 Newbie
Joined: 10 Mar 2003 Posts: 3 Location: Canada
|
Posted: Mon Mar 10, 2003 3:33 pm |
Hi again.
What am i doing wrong here ?
Mud output is like this:
sack (carried) :
a tiny stone key
a crude metal key
a saddlecloth
My trigger is like this:
(in pattern field)
sack ~(carried~) : ${(%w)$} ${(%w)$} ${(%w)$}
(in value field)
#VAR item1 {%1};#VAR item2 {%2};#VAR item3 {%3}
idea would be @item1 as "key"
@item2 "key"
@item3 "saddlecloth"
I hope i am close... but still cant figure it out by myself
Thank You. |
|
|
|
Kjata GURU
Joined: 10 Oct 2000 Posts: 4379 Location: USA
|
Posted: Mon Mar 10, 2003 4:23 pm |
You are close, but you need to take into consideration the possible text that may appear between the end of one line and the last word of the next line. For that, change your pattern to this:
sack ~(carried~) :$* (%w)$* (%w)$* (%w)$
Now, all of the other words except the last one (like "a tiny stone", "a crude metal", and "a", in this case) will be matched by the *'s.
Kjata |
|
|
|
Emit Magician
Joined: 24 Feb 2001 Posts: 342 Location: USA
|
Posted: Mon Mar 10, 2003 4:25 pm |
yes, you are getting close. Where your pattern has this in it:
${(%w)}$
It will only match a line with one word. Also, the curly brackets are unnecessary. To modify the trigger you have now:
Pattern:
sack ~(carried~) : $*(%w)$*(%w)$*(%w)$
The * wildcard will match anything except for zmud special characters. However, this will only work when your sack has exactly three things in it. A more flexible way is this:
#TRIGGER "InvTrig" {sack ~(carried~)} {
#var items ""
#TEMP {^$} {#state InvTrig 0}}
#COND {(%w)$} {#ADDITEM items %1} {WithinLines|Param=99}
This is a trigger with two states. The first line is the command to create the trigger, name it, and set its pattern. The second two lines are the commands for the first state, the will execute on the pattern
sack (carried)
The last line (#COND) is the second state for the trigger. It will execute on each of the 99 lines following "sack (carried)" until a blank line is sent. When a blank line comes, the #TEMP trigger is executed, and it reverts the "InvTrig" to its original state.
After the trigger executes, you have a stringlist named "items" that contains all of the keywords for the items in the sack. There are several things you can do with a string list. Read the help->reference page in the String List section to get an idea of the things you can use it for.
--------
moon.icebound.net:9000 |
|
|
|
|
|