|
Dargen Newbie
Joined: 15 Oct 2016 Posts: 4
|
Posted: Sat Oct 15, 2016 7:10 pm
String / Trigger help |
Can anyone help me with a Trigger to capture text and put the captured pattern into a string list. The Present trigger i use only captures 1 line and the text is over many lines.
Below is a capture of the entire text received
Mallibett regards you fiercely, and then darts so close his lips press against your ear. "Rock-face mine, Subterranean road before a gate, Twisting pathway,
Cavern with entrance, Cave leading outside, Rock-face mine, Square cut tunnel, Near the foot of the stairs, Stepped tunnel section, Rock passage, Turn in the
dark passage, Southern end of the mine, Secret valley, Field by mountains, these I see, these I see," he whispers.
1759h, 1719m efL -
So i would like to capture all those locations (excluding the rock-face mine) into a string list. The number of mines active changes and the number shown in text example is random
and could be only 1 line long 2 lines long or in this case 3
My failed attempts either captured the 1st line or last line
thanks for any any help,
[b]Dargen |
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4691 Location: Pensacola, FL, USA
|
Posted: Sun Oct 16, 2016 1:27 am |
You need a multistate trigger for this, and you need to do error checking to see if the current result is enough.
Something like this should work.
Code: |
#TR {^Mallibett regards you fiercely, and then darts so close his lips press against your ear. "(*)$} {
mineList=%1
#IF (%match(%line, "whispers.")) {#STATE 0;#RAISE mineEnd}
}
#COND {*} {
mineList=%concat(@mineList, %line)
#IF (%match(%line, "whispers.")) {#RAISE mineEnd} {#STATE 1}
} {Within|Param=1}
#EVENT mineEnd {
minelist=%replace(@minelist, "these I see,", "")
mineList=%replace(@mineList, ", ", "|")
#VAR mineList %delItem(%item(@mineList, %numitems(@mineList)) ,@mineList)
} |
|
|
_________________ Discord: Shalimarwildcat |
|
|
|
Vijilante SubAdmin
Joined: 18 Nov 2001 Posts: 5182
|
Posted: Sun Oct 16, 2016 6:22 pm |
Small change suggestion:
Code: |
#EVENT mineEnd {
mineList=%replace(@mineList, ", these I see", "")
mineList=%replace(@mineList, ","" he whispers.", "")
mineList=%replace(@mineList, ", ", "|")
} |
I would tend to use %subregex to put all the replacements together
Code: |
#EVENT mineEnd {mineList=%subregex(@mineList, "(?:, these I see|,"" he whispers\.|(, ))", "(?(1)\|)")} |
|
|
_________________ The only good questions are the ones we have never answered before.
Search the Forums
Last edited by Vijilante on Sun Oct 16, 2016 8:49 pm; edited 1 time in total |
|
|
|
Dargen Newbie
Joined: 15 Oct 2016 Posts: 4
|
Posted: Sun Oct 16, 2016 6:52 pm |
Have copied and pasted the code into Cmud and it will only pick up the first line.
So have i got the correct trigger defined ? Im using pattern .
mineList=%1
#show @minelist
#IF (%match(%line, "whispers.")) {#STATE 0;#RAISE mineEnd}
#cond {*} {
mineList=%concat(@mineList,%line)
#IF (%match(%line,"whispers.")) {#RAISE mineEnd} {#STATE 1}
} {Within|Param=1}
above are the lines entered into the trigger script text |
|
|
|
Vijilante SubAdmin
Joined: 18 Nov 2001 Posts: 5182
|
Posted: Sun Oct 16, 2016 8:55 pm |
I think the problem was a matter of spacing in shalimar's post. You should have a trigger with a pattern of:
Code: |
^Mallibett regards you fiercely, and then darts so close his lips press against your ear. "(*)$ |
The script of that trigger:
Code: |
mineList=%1
#IF (%match(%line, "whispers.")) {#STATE 0;#RAISE mineEnd} |
That trigger should then have a sub-state with a pattern of:
The sub-state script should be
Code: |
mineList=%concat(@mineList, %line)
#IF (%match(%line, "whispers.")) {#RAISE mineEnd} {#STATE 1} |
The sub-state should have a type of Within Lines and a parameter of 1.
You should also have an event named mineEnd with a script of:
Code: |
minelist=%replace(@minelist, "these I see,", "")
mineList=%replace(@mineList, ", ", "|")
#VAR mineList %delItem(%item(@mineList, %numitems(@mineList)) ,@mineList) |
You may choose to use one of the alternate script suggestions I made for the mineEnd event. |
|
_________________ The only good questions are the ones we have never answered before.
Search the Forums |
|
|
|
Dargen Newbie
Joined: 15 Oct 2016 Posts: 4
|
Posted: Mon Oct 17, 2016 11:41 am |
it does look the same ?
#IF (%match(%line,"whispers.")) {#RAISE mineEnd} {#STATE 1} } {Within|Param=1} <-- line on one line instead of wrapped to nextline
what i gather from you is that the "space" after "," and before "whispers" is important . Maybe my pattern type is wrong or brackets wrong
the trigger does fire and does collect the first line but then it stops almost as if its matching whispers too early and not checking the lines in between the first trigger
and whispers (closing condition)
i have a #show @minelist to see what has gone into the variable and the i type #var directly to check after as well
Thanks for all your help guys as you can see im a complete idiot... |
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4691 Location: Pensacola, FL, USA
|
Posted: Mon Oct 17, 2016 1:37 pm |
Here is the XML of the class i made originally trying to get it to work off the sample data you supplied
Try pasting this over the information on the XML tab of a new class.
Just remember to delete/disable the old version.
Code: |
<class name="mineCapture" id="1949">
<trigger priority="19440" id="1944">
<pattern>^Mallibett regards you fiercely, and then darts so close his lips press against your ear. "(*)$</pattern>
<value>mineList=%1
#IF (%match(%line, "whispers.")) {#STATE 0;#RAISE mineEnd}</value>
<trigger type="Within Lines" param="1">
<pattern>*</pattern>
<value>mineList=%concat(@mineList, %line)
#IF (%match(%line, "whispers.")) {#RAISE mineEnd} {#STATE 1}</value>
</trigger>
</trigger>
<event event="mineEnd" priority="19460" id="1946">
<value>minelist=%replace(@minelist, "these I see,", "")
mineList=%replace(@mineList, ", ", "|")
#VAR mineList %delItem(%item(@mineList, %numitems(@mineList)) ,@mineList) </value>
</event>
</class> |
|
|
_________________ Discord: Shalimarwildcat |
|
|
|
Dargen Newbie
Joined: 15 Oct 2016 Posts: 4
|
Posted: Mon Oct 17, 2016 6:58 pm |
Eureka !!!
it works - my thanks to both of you |
|
|
|
|
|
|
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
|
|