Brackets and my trouble

Posted by Magellan on Mon 13 Nov 2017 03:10 AM — 3 posts, 13,694 views.

#0
without too much preamble here, i have a trigger set to collect some data off the prompt line. it works unless i enter a room that adds one or more set of brackets.



[695, 770]<552hp 496sp 499st> 



the trigger pulls everything you see there and sets it all as variables. it also throws out a second prompt line that shows some information i want. i didn't include it in these examples because they are in reaction to the line i did include.

so this is what happens if i go into another room with a visible flag:


[SAFE][695, 770]<5000hp 4968sp 4998st> 
Run-time error
World: [NDA]
Immediate execution
[string "Alias: "]:7: attempt to perform arithmetic on a string value
stack traceback:
        [string "Alias: "]:7: in main chunk
        [C]: in function 'Execute'
        [string "Trigger: "]:4: in main chunk



here is the trigger:


<triggers>
  <trigger
   enabled="y"
   expand_variables="y"
   group="affects"
   keep_evaluating="y"
   match="\[(.*?)\, (.*?)\]\&lt;[0-9]+hp [0-9]+sp [0-9]+st\&gt; $"
   omit_from_log="y"
   regexp="y"
   send_to="14"
   sequence="200"
  >
  <send>ColourNote ("blue", "black", "[", "gray", "black", "@Combat", "@mCa", "black", " Trgt","blue", "black","] ADIR @DIR waypoint @wpX,@wpY - return val @rX,@rY")
SetVariable ("X", "%1")
SetVariable ("Y", "%2")
Execute("return")
Execute("rcp")</send>
  </trigger>
</triggers>


i realize this is somewhat ugly. and i know that the error is that it is seeing the first set of brackets and then the line triggers and it's trying to do 'arithmetic' on a non-numerical line. i tried making it so it was only looking specifically for the lines i want, and removed the portion that would look for the start of a line hoping it would just ignore the [SAFE] bracket when it pops up. what do i need to do to make it ignore flags when they pop up. this is something that happens frequently and doesn't really affect the trigger but the annoying error is distracting. i appreciate the input.
Amended on Mon 13 Nov 2017 05:50 AM by Fiendish
USA Global Moderator #1
When I have something that sometimes appears on a line, I make my regular expression expect it "maybe" by using the question mark symbol. Also escaping a comma isn't necessary.

So where you have

\[(.*?)\, (.*?)\]

I would put

(\[.*\])?\[(\d+), (\d+)\]
Amended on Mon 13 Nov 2017 05:49 AM by Fiendish
#2
Thanks Fiendish. A Gentleman Scholar as always!