Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
Dumas
Enchanter


Joined: 11 Feb 2003
Posts: 511
Location: USA

PostPosted: 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?
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: 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.
Reply with quote
Dumas
Enchanter


Joined: 11 Feb 2003
Posts: 511
Location: USA

PostPosted: 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.
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: 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).
Reply with quote
Anaristos
Sorcerer


Joined: 17 Jul 2007
Posts: 821
Location: California

PostPosted: 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.
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: 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".
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: 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
Reply with quote
Dumas
Enchanter


Joined: 11 Feb 2003
Posts: 511
Location: USA

PostPosted: 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.
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: 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
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
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

© 2009 Zugg Software. Hosted by Wolfpaw.net