|
geosmith Wanderer
Joined: 23 Apr 2005 Posts: 57
|
Posted: Wed Jun 22, 2005 11:21 am
Multiline triggers? |
I realise the answer's probably "no", but is it possible to create a trigger where any part of the sentence might appear on one line, and any part on the next?
For example, if the trigger pattern was "A sword is here.", would it be possible to have that triggering off lines such as...
Blahblahblah. A
sword is here.
Blahblah. A sword
is here.
... etc. without specifying which words are going to appear on which lines?
Any advice would be appreciated. |
|
|
|
KillerKitty Beginner
Joined: 15 Jun 2005 Posts: 21
|
Posted: Wed Jun 22, 2005 3:53 pm |
I have read in the help files that you can't do it in a normal trigger but you can if you make the Pattern a regex pattern.. check the box beneath the bit where you type it in in the trigger window..
\n is new line apparently, but I have not been able to get multi-line triggers working myself either. That should help a bit though.. Help file has more on regex.. |
|
|
|
Mortis Beginner
Joined: 10 Feb 2004 Posts: 21 Location: Sweden
|
Posted: Wed Jun 22, 2005 4:23 pm |
I have no idea how regex patterns work. I have never used them. So I can't comment if they could help.
But you could do like this.
Perhaps it's not an optimal solution but it worked..
Code: |
#trigger {(*)$(*)} {#IF (%pos("A sword is here.",%1%2)) {#say yes}} |
It works with those exemples you wrote.
But keep in mind that this trigger will not work if "sword" doesnt have a space behind it.
If you type
"A sword"
"is here."
it will read "A swordis here"
You could always all spaces with nothing. %replace(%1%2," ","")
and change ifcheck to "Aswordishere."
but iam sure there is a more cleaver way to do this. This feel a bit brute force.. |
|
_________________ When you lose, dont lose the lesson. |
|
|
|
KillerKitty Beginner
Joined: 15 Jun 2005 Posts: 21
|
Posted: Wed Jun 22, 2005 5:16 pm |
zMUD definitely supports multi-line triggers, I read it somewhere... I just found this, which looks like it could be useful:
Quote: |
(From http://www.zuggsoft.com/library/trigadv.htm)
The "Within Lines" type will fire the trigger if the pattern is received within the next N lines. For example:
#TRIGGER {Zugg} {#CW high,red}
#COND {Hello} {#CW high,blue} {Within|Param=5}
This will wait for the "Zugg" text from the MUD. Then, if "Hello" is received within the next 5 lines of text, it will be colored bright blue. If 5 lines are received without seeing the "Hello" text, the trigger resets (it does not advance to the next state).
This is one way to handle a multi-line trigger. For example:
#TRIGGER {Pattern1} {}
#COND {Pattern2} {command} {Within|Param=1}
This would only execute the "command" if the Pattern2 was on the line immediately following Pattern1. In previous versions of zMUD you could emulate this with:
#TRIGGER {Pattern1$Pattern2} {command}
Seems simpler, but this old multi-line trigger is much slower to process than the new Within syntax. Also, the Within syntax allows you to match more than just two lines. For example:
#TRIGGER {Pattern1} {}
#COND {Pattern2} {} {Within|Param=1}
#COND {Pattern3} {command} {Within|Param=1} |
|
|
|
|
Guinn Wizard
Joined: 03 Mar 2001 Posts: 1127 Location: London
|
Posted: Wed Jun 22, 2005 6:29 pm |
Crikey, never knew you could split triggers across lines using a regex. Gonna have to remember that in future, thanks KK
So with that and using %pos in mind...
Code: |
#REGEX {Start(.*)\n(.*)Stop} {#IF (%pos( Test123, %1%2) != 0) {#SAY Bingo}} |
Then to test, type
Code: |
#say StartasdTes;#say t123asdStop |
which should fire
Code: |
#say StartasdTes;#say t12asdStop |
which shouldn't
I'm sure someone else can improve upon it, but I'm off out |
|
|
|
|
|