|
ryan0_o Beginner
Joined: 17 Aug 2016 Posts: 19
|
Posted: Sat Aug 20, 2016 12:42 pm
Multi-Line Triggers |
I was looking for a way to do something like this:
#trigger {Trigger on this line that is known}
if the next like doesn't contain (this or this) do some formatting to the line with #sub.
I skimmed the helpfiles and couldn't find anything in the #events like receivedline or the sort and am I bit lost where to start.
Also assuming I'll need something to stop the trigger from firing on every line thereafter. I think the #waitsignal while accomplish this though. |
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4690 Location: Pensacola, FL, USA
|
Posted: Sat Aug 20, 2016 1:52 pm |
#TRIGGER {first line} {}
#COND {*} {#IF (!%match(%line, {this|that})) {#SUB something}}
in the GUI, you can choose a new trigger state to create the condition. |
|
_________________ Discord: Shalimarwildcat |
|
|
|
Vijilante SubAdmin
Joined: 18 Nov 2001 Posts: 5182
|
Posted: Sat Aug 20, 2016 6:08 pm |
It might be better to build the match components directly into the pattern of the second state. Depending on the complexity you might need to use a regex. Also you will probably want to limit the second state to matching only the next line using the WITHIN LINES trigger type.
#TRIGGER {known line} {}
#COND {{this|this}} {#SUB {some stuff}} {within|param=1}
More complex substitutions can be built by capturing parts of the line and testing the content, but again a regex might be needed for the more complex captures. |
|
_________________ The only good questions are the ones we have never answered before.
Search the Forums |
|
|
|
ryan0_o Beginner
Joined: 17 Aug 2016 Posts: 19
|
Posted: Sun Aug 21, 2016 12:47 pm |
Code: |
#TRIG {^***** Range (%d) *****} {
#var range %1
#CON {*} {
#if (%match(%line,You scan {*}) {
#UNCON {*}
} {
#SUB {%line} {(@range @scanDir) %line}
}
}
|
Getting illegal token error. I've tried escaping the "*"s in the triggers to no avail. |
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4690 Location: Pensacola, FL, USA
|
Posted: Sun Aug 21, 2016 1:17 pm |
i suspect its the #UNCON command, that doesn't exist.
Also, #SUB only needs on parameter inside a trigger, giving it more will create a separate #TRIGGER, which I dont think you are wanting.
Also, since we are using a string instead of an anonymous variable inside %match, we should wrap it in quotes.
#TRIG {^~*~*~*~*~* Range (%d) ~*~*~*~*~*} {#var range %1}
#COND {^*$} {#if (%match(%line, "You scan")) {#SUB {(@range @scanDir) %line}}} {within|param=1} |
|
_________________ Discord: Shalimarwildcat
Last edited by shalimar on Sun Aug 21, 2016 1:20 pm; edited 1 time in total |
|
|
|
ryan0_o Beginner
Joined: 17 Aug 2016 Posts: 19
|
Posted: Sun Aug 21, 2016 1:19 pm |
Vijilante wrote: |
It might be better to build the match components directly into the pattern of the second state. Depending on the complexity you might need to use a regex. Also you will probably want to limit the second state to matching only the next line using the WITHIN LINES trigger type.
#TRIGGER {known line} {}
#COND {{this|this}} {#SUB {some stuff}} {within|param=1}
More complex substitutions can be built by capturing parts of the line and testing the content, but again a regex might be needed for the more complex captures. |
Quote: |
You scan north.
You scan south.
You scan east.
You scan west.
***** Range 1 *****
One of the elite elven guardsmen is standing watch here.
You scan up.
***** Range 1 *****
An immaculately dressed elven palace guard holds her post here.
A young elven shapechanger keeps a look out for intruders here.
You scan down.
|
Basically I am wanting to simplify this to something like:
Quote: |
(3 west) One of the elite elven guardsmen is standing watch here.
(1 up) An immaculately dressed elven palace guard holds her post here.
(1 up) A young elven shapechanger keeps a look out for intruders here.
|
|
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4690 Location: Pensacola, FL, USA
|
Posted: Sun Aug 21, 2016 1:24 pm |
Aha, that changes things
#TRIG {^~*~*~*~*~* Range (%d) ~*~*~*~*~*} {#var range %1}
#COND {^*$} {#if ((!%match(%line, "You scan") OR (%line=%null)) {
#SUB {(@range @scanDir) %line}
#STATE 1
}} {
Hmm... is the a line that appears when you are done scanning?
Cause I can see this getting stuck in the second state.
Adding that second #IF clause might help. |
|
_________________ Discord: Shalimarwildcat
Last edited by shalimar on Sun Aug 21, 2016 1:29 pm; edited 1 time in total |
|
|
|
ryan0_o Beginner
Joined: 17 Aug 2016 Posts: 19
|
Posted: Sun Aug 21, 2016 1:28 pm |
Thanks, Ill give it a shot.
I was just looking into #STATE. The helpfile is a bit ambiguous on it's use. |
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4690 Location: Pensacola, FL, USA
|
Posted: Sun Aug 21, 2016 1:33 pm |
#TRIG {^~*~*~*~*~* Range (%d) ~*~*~*~*~*} {#var range %1}
#COND {^*$} {
#IF (%line=%null) {#EXIT}
#if (!%match(%line, "You scan") ) {
#SUB {(@range @scanDir) %line}
#STATE 1
}
} |
|
_________________ Discord: Shalimarwildcat
Last edited by shalimar on Sun Aug 21, 2016 1:34 pm; edited 1 time in total |
|
|
|
ryan0_o Beginner
Joined: 17 Aug 2016 Posts: 19
|
Posted: Sun Aug 21, 2016 1:33 pm |
I feel like it will help with me keeping it fire on every single line. I need I way to turn it off once I'm done with it.
|
|
|
|
ryan0_o Beginner
Joined: 17 Aug 2016 Posts: 19
|
Posted: Sun Aug 21, 2016 1:35 pm |
shalimar wrote: |
#TRIG {^~*~*~*~*~* Range (%d) ~*~*~*~*~*} {#var range %1}
#COND {^*$} {
#if (!%match(%line, "You scan") ) {
#SUB {(@range @scanDir) %line}
#STATE 1
}
#IF (%line=%null) {#STATE 0}
} |
Got ya! Gonna use my prompt to change to state to zero. Should work, thanks! |
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4690 Location: Pensacola, FL, USA
|
Posted: Sun Aug 21, 2016 1:35 pm |
Yea, thats why i am testing for null and stopping it early
|
|
_________________ Discord: Shalimarwildcat |
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4690 Location: Pensacola, FL, USA
|
Posted: Sun Aug 21, 2016 1:37 pm |
You will need to give this one trigger an ID if you want to be able to change its state from another trigger.
And I apparently edited it since you quoted it, sorry about that.
I'm not used to people being so on top of my suggestions. |
|
_________________ Discord: Shalimarwildcat |
|
|
|
ryan0_o Beginner
Joined: 17 Aug 2016 Posts: 19
|
Posted: Mon Aug 22, 2016 12:14 pm |
Code: |
#TRIG {^~*~*~*~*~* Range (%d) ~*~*~*~*~*} {
#var range %1
#COND {^*$} {
#if (!%match(%line, "You scan")) {
#SUB {(@range @scanDir) %line}
#STATE 1
} {
#if (%match(%line,"<")) {#STATE 0} <--- my prompt turns it off
}
}
}
|
Is giving me this:
Quote: |
You scan north.
***** Range 1 *****
(1 ) An elven citizen is calmly taking care of her tasks.
(1 )
You scan south.
You scan east.
***** Range 1 *****
(1 ) An imposing elven guardsman is keeping an eye out for trouble.
(1 ) An imposing elven guardsman is keeping an eye out for trouble.
(1 )
(1 ) ***** Range 3 *****
(1 ) One of the elite elven guardsmen is standing watch here.
(1 ) An imposing elven guardsman is keeping an eye out for trouble.
(1 ) A seductive sirine selling dresses from the Islands has set up a booth here.
(1 )
You scan west.
You scan up.
You scan down.
|
Basically I need to put a conditional for empty lines to gag. I'll also gag the ranges. But I think the substitutes are causing my trigger to not fire and set my Range variable... do substitutes work that way? |
|
|
|
ryan0_o Beginner
Joined: 17 Aug 2016 Posts: 19
|
Posted: Mon Aug 22, 2016 12:48 pm |
More tinkering gets me this:
Quote: |
You scan north.
You scan south.
***** Range 1 *****
(1 south) Jorgen the jeweler is here inspecting some jewelry.
You scan east.
***** Range 1 *****
(1 east) A watchman patrols the streets of Udgaard.
A jaette man-at-arms is here protecting the city.
You scan west.
***** Range 1 *****
(1 west) A stray dog runs around the streets looking for something to chase.
A jaette soldier strides through the city.
A fire giant stands here with folded arms watching the bank transactions.
A fire giant stands here with folded arms watching the bank transactions.
You scan up.
You scan down.
|
With this code:
Code: |
#TRIG {^~*~*~*~*~* Range (%d) ~*~*~*~*~*} {
#var range %1
#COND {^*$} {
#if (!%match(%line, "You scan")) {
#SUB {(@range @scanDir) %line}
#STATE {scan} {1}
} {
#if (%match(%line,"<")) {#STATE {scan} 0}
}
}
}
|
|
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4690 Location: Pensacola, FL, USA
|
Posted: Mon Aug 22, 2016 1:10 pm |
Did you actually try my edited version with the #EXIT in there?
Code: |
#TRIG {^~*~*~*~*~* Range (%d) ~*~*~*~*~*} {#var range %1}
#COND {^*$} {
#IF (%line=%null) {#EXIT}
#if (!%match(%line, "You scan") ) {
#SUB {(@range @scanDir) %line}
#STATE 1
}
} |
|
|
_________________ Discord: Shalimarwildcat |
|
|
|
ryan0_o Beginner
Joined: 17 Aug 2016 Posts: 19
|
Posted: Mon Aug 22, 2016 9:39 pm |
I'll give it a shot when I get a chance. Also thought of a custom function with a #switch and #default.
|
|
|
|
ryan0_o Beginner
Joined: 17 Aug 2016 Posts: 19
|
Posted: Tue Aug 23, 2016 3:18 pm |
Tried your recommendation and got a parsing error.
The above code works but I suspect it's getting turned off prematurely somehow. |
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4690 Location: Pensacola, FL, USA
|
Posted: Tue Aug 23, 2016 4:00 pm |
Odd... I got the same thing trying to enter it on the command line.... try entering it Via XML instead.
Make a new trigger, switch to the XML tab, and paste this over the current value:
Code: |
<trigger priority="9940" id="994">
<pattern>^~*~*~*~*~* Range (%d) ~*~*~*~*~*</pattern>
<value>#var range %1</value>
<trigger type="Within Lines" param="1">
<pattern>^*$</pattern>
<value>#IF (%line=%null) {#EXIT}
#if (!%match( %line, "You scan")) {
#SUB {(@range @scanDir) %line}
#STATE 1
} </value>
</trigger>
</trigger> |
Edited to fix second pattern. This works on my end. |
|
_________________ Discord: Shalimarwildcat |
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4690 Location: Pensacola, FL, USA
|
Posted: Tue Aug 23, 2016 4:26 pm |
Retesting it... it seems to insert a space after the 1 in the #STATE command, removing that fixed it for me.
|
|
_________________ Discord: Shalimarwildcat |
|
|
|
ryan0_o Beginner
Joined: 17 Aug 2016 Posts: 19
|
Posted: Wed Aug 24, 2016 1:28 pm |
Quote: |
You scan north.
You scan south.
***** Range 1 *****
(1 south) A cloaked woman with dark, shifty eyes beckons you to examine her wares.
ERROR: Trigger "^*$" fired but did not compile
***** Range 2 *****
(2 south) A drunken sailor staggers about, trying to maintain his balance.
ERROR: Trigger "^*$" fired but did not compile
A lean dockman is here, swiftly securing ships to the docks.
***** Range 4 *****
(4 south) A small brown tadpole struggles to swim upstream.
ERROR: Trigger "^*$" fired but did not compile
|
Not sure what the problem is. Doing similar to what my trigger did. Firing only on the first instance of {^*$}. Or so it would appear. |
|
|
|
ryan0_o Beginner
Joined: 17 Aug 2016 Posts: 19
|
Posted: Wed Aug 24, 2016 1:29 pm |
If you don't have an alternative, I may try gagging it all and making a list(s) then sorting/printing.
Boggling me why this isn't working. |
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4690 Location: Pensacola, FL, USA
|
Posted: Wed Aug 24, 2016 1:42 pm |
I have the fix posted right after the code.... remove the space after the 1.
Did you delete your trigger, or are both still active?
I am guessing yours is giving the single results, and mine isnt firing because the space wasnt removed. |
|
_________________ Discord: Shalimarwildcat |
|
|
|
ryan0_o Beginner
Joined: 17 Aug 2016 Posts: 19
|
Posted: Thu Aug 25, 2016 4:06 am |
shalimar wrote: |
I have the fix posted right after the code.... remove the space after the 1.
Did you delete your trigger, or are both still active?
I am guessing yours is giving the single results, and mine isnt firing because the space wasnt removed. |
I removed the space. Both triggers give the same result. Firing on the first instance of {^*} only. Or at least appearing to.
The only difference is the XML trigger gave the above compiling errors after the first time the wildcard trigger fired.
Are line breaks added automatically after substitutes? |
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4690 Location: Pensacola, FL, USA
|
Posted: Thu Aug 25, 2016 4:37 am |
You need to use ^*$ not just ^* to force it to grab the whole line
^ is the start of line anchor
$ is the end of line anchor
I was getting odd results without using both.
Try disabling your trigger when you test mine, and vice versa.
Are you still getting those errors after the edit?
If so, go into the GUI settings editor for the trigger, then under the editor menu, you can check your syntax to find out what line the error is on. |
|
_________________ Discord: Shalimarwildcat |
|
|
|
|
|