AddTrigger parsing escaped characters

Posted by Rollanz on Sun 17 Aug 2014 04:23 PM — 5 posts, 21,124 views.

#0
I am trying to make an alias for highlighting names using AddTrigger function. However, the AddTrigger function is parsing [[\b]] string that I'm using to delimit the words. The code I'm using is below.


blank=[[\b]]
highlightFormat=blank.."%1"..blank
triggerName="%1".."Highlight"

AddTrigger(triggerName, highlightFormat, "", trigger_flag.Enabled+trigger_flag.RegularExpression+trigger_flag.KeepEvaluating+trigger_flag.IgnoreCase+trigger_flag.Replace, custom_colour.Custom3, 0, "", "")


What I'm trying to get is a trigger along the lines of "\bRollanz\b"

What's I'm getting instead:
Rollanz Something not displayable on the forum.

Thanks in advance.
Amended on Sun 17 Aug 2014 08:09 PM by Nick Gammon
Australia Forum Administrator #1
Template:version
Please help us by advising the version of MUSHclient you are using. Use the Help menu -> About MUSHclient.


I can't reproduce that.

In the Immediate window I tried:


blank=[[\b]]
highlightFormat=blank.."foo"..blank
triggerName="foo".."Highlight"

check (AddTrigger(triggerName, highlightFormat, "", trigger_flag.Enabled+trigger_flag.RegularExpression+trigger_flag.KeepEvaluating+trigger_flag.IgnoreCase+trigger_flag.Replace, custom_colour.Custom3, 0, "", ""))


The resulting trigger was:


<triggers>
  <trigger
   custom_colour="3"
   enabled="y"
   ignore_case="y"
   keep_evaluating="y"
   match="\bfoo\b"
   name="fooHighlight"
   regexp="y"
   sequence="100"
   variable="fooHighlight"
  >
  </trigger>
</triggers>


So it looks like it worked OK.
Australia Forum Administrator #2
See: http://www.gammon.com.au/scripts/doc.php?dialog=IDD_PREFS_P9

Scroll down to: Translate Backslash Sequences

Maybe the \b is being turned into a backspace, so try making it: \\b
Amended on Sun 17 Aug 2014 10:05 PM by Nick Gammon
#3
[[\\b]] worked, and it was the only combination of \ and [ and " I hadn't tried yet.

A couple of curious observations:
1) I did not have the "translate backslash sequences" box checked, and checking/unchecking it did not seem to make a difference to the resulting trigger.

2) "\\b" did not while [[\\b]] did.

Could me having language for non-unicode programs set to English(Canada) have something to do with the unusual result?
Australia Forum Administrator #4
I wouldn't think Unicode is the problem.

Your non-printable characters in your first post are indeed 0x08 characters, that is, backspace.

The option "translate backslash sequences" only applies to the command window, not to the Send box in triggers/aliases which unconditionally translate them. This can be annoying because it means in Lua you then need to double the backslashes, or even quadruple them if you use normal Lua strings, eg.


"\\\\b" 


This is because the MUSHclient processing converts that to:



"\\b" 


And then Lua string processing converts it to:


"\b" 


Except that in the square brackets backslashes are ignored by Lua, so you don't need to quadruple them, only double them.

If you use a script file (and put the function name in the script box) then you drop down to normal Lua behaviour, which halves the number of backslashes needed.