|
Dumas Enchanter
Joined: 11 Feb 2003 Posts: 511 Location: USA
|
Posted: Sat May 19, 2012 10:57 pm
Looping Trigger Help |
Had a simple trigger that worked fine until I fiddled with it to remove using #ALARM. Unfortunately, now the trigger only fires once.
My setup trigger: ^(\a+)\d+\s+(.+)$
Action is to simply add the data to a database variable.
This stays enabled until it receives a specific line (typically within a few lines but not always the same) which then disables the trigger.
Problem is, only the very first line of a list of items is being captured and added to the variable.
For example:
item3333 this item
another4444 another item
athird5555 third item
Should store all three items (and it used to using an alarm to disable the trigger). But, using trigger states, only the first line is being captured. Any thoughts? |
|
|
|
Rahab Wizard
Joined: 22 Mar 2007 Posts: 2320
|
Posted: Sun May 20, 2012 12:54 am |
Please give us the actual code, preferably the XML code, enclosed in [code]...[/code] tags. Both the capture trigger, and whatever code turns it off.
|
|
|
|
Dumas Enchanter
Joined: 11 Feb 2003 Posts: 511 Location: USA
|
Posted: Sun May 20, 2012 1:15 pm |
full trigger:
Code: |
<trigger name="get_info" param="2000" priority="127830" regex="true" enabled="false" id="12783">
<pattern>^(\a+)\d+\s+(.+)$</pattern>
<value>#ADDKEY room_info {%1} %2
</value>
<trigger regex="true">
<pattern>Number of objects\:</pattern>
<value>#T- {get_info}
#SHOW GO GO GO
#T- {ih_more}
#T- {no_obj}</value>
</trigger>
</trigger> |
Enabling code is just a called alias to enable the trigger. |
|
|
|
Rahab Wizard
Joined: 22 Mar 2007 Posts: 2320
|
Posted: Sun May 20, 2012 2:51 pm |
The problem is that you have made this a multi-state trigger. The trigger starts out in state 1. It captures the first line of data, modifies the database variable, and switches to state 2. State 2 waits until it captures "Number of objects", switches back to state 1, and turns the entire trigger off.
What you need are two separate single-state triggers: The get_info trigger to capture the data, and a second separate trigger to turn off the get_info trigger (and probably itself). |
|
|
|
Anaristos Sorcerer
Joined: 17 Jul 2007 Posts: 821 Location: California
|
Posted: Mon May 21, 2012 7:48 pm |
You can play with this idea:
Code: |
<trigger name="get_info" type="Loop Pattern" param="2000" priority="127830" regex="true" id="1">
<pattern>^(\a+)\d+\s+(.+)$</pattern>
<value>#TEMP {^Number of objects\:$} {endproc} "" "regex"
;;
#ADDKEY room_info {%1} %2</value>
</trigger>
<alias name="endproc" id="3">
<value>#T- {get_info}
#SHOW GO GO GO
#T- {ih_more}
#T- {no_obj}</value>
</alias>
|
|
|
_________________ Sic itur ad astra. |
|
|
|
Rahab Wizard
Joined: 22 Mar 2007 Posts: 2320
|
Posted: Mon May 21, 2012 8:07 pm |
Anaristos, that seems rather wasteful. There's no need to make that trigger a Loop trigger at all; a normal trigger will work fine. And if you have 5 lines of data in a set before the "Number of objects" line, you end up making the TEMP trigger five times. It is much more efficient to simply have a permanent trigger for "Number of objects".
|
|
|
|
MattLofton GURU
Joined: 23 Dec 2000 Posts: 4834 Location: USA
|
Posted: Mon May 21, 2012 10:01 pm |
Depending on the uniqueness of the formatting for the item lines, you could even use just a Within Lines trigger and forget about the one for the Number of objects line.
|
|
_________________ EDIT: I didn't like my old signature |
|
|
|
Dumas Enchanter
Joined: 11 Feb 2003 Posts: 511 Location: USA
|
Posted: Wed May 23, 2012 9:49 pm |
The problem with Within Lines, if I am reading about it right, is that it will stop after a set number of lines. If there isn't enough on the setting, it will miss some. If it is set too high, then it will not disable the trigger like I want it to in between checks. I went back to the permanent trigger method and it works fine again.
|
|
|
|
MattLofton GURU
Joined: 23 Dec 2000 Posts: 4834 Location: USA
|
Posted: Fri May 25, 2012 7:32 pm |
Quote: |
The problem with Within Lines, if I am reading about it right, is that it will stop after a set number of lines.
|
You're doing it wrong. Just like a simple Pattern type, a Within Lines type matches just once, executes its code, and then advances the active trigger state to the next condition (or back to 0 if there isn't anything more). The difference between them is that Pattern can only ever match on the current line while Within Lines can make the match on current + N lines. The param for this state type is N, so for the typical list of stuff sent by the game N should be set to 1
Now, obviously, you don't want just one line matched. At this point, you can use the #STATE command to reactivate the Within Lines state so that it will match the next line. This essentially causes the within lines state to loop for however many lines are in the list. The real beauty of this state is that when it fails to find a match, it automatically resets the trigger state to 0. There's no need for alarms or using #T+/#T- to keep the order of various triggers right.
This does generally mean you cannot have any more states after that within lines state, but if the order of the list is fixed (ie, you know what the last item is going to be) you can use an #IF or other conditional to test for that in order to pick the right number to use with #STATE. |
|
_________________ EDIT: I didn't like my old signature |
|
|
|
|
|