Gammon Forum
Entire forum
MUSHclient
Lua
AddTrigger parsing escaped characters
AddTrigger parsing escaped characters
|
It is now over 60 days since the last post. This thread is closed.
  Refresh page
Posted by
| Rollanz
(26 posts) bio
|
Date
| Sun 17 Aug 2014 04:23 PM (UTC) Amended on Sun 17 Aug 2014 08:09 PM (UTC) by Nick Gammon
|
Message
| 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. | top |
|
Posted by
| Nick Gammon
Australia (22,975 posts) bio
Forum Administrator |
Date
| Reply #1 on Sun 17 Aug 2014 08:12 PM (UTC) |
Message
|
|
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. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | top |
|
Posted by
| Nick Gammon
Australia (22,975 posts) bio
Forum Administrator |
Date
| Reply #2 on Sun 17 Aug 2014 10:04 PM (UTC) Amended on Sun 17 Aug 2014 10:05 PM (UTC) by Nick Gammon
|
Message
| |
Posted by
| Rollanz
(26 posts) bio
|
Date
| Reply #3 on Sun 17 Aug 2014 11:40 PM (UTC) |
Message
| [[\\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? | top |
|
Posted by
| Nick Gammon
Australia (22,975 posts) bio
Forum Administrator |
Date
| Reply #4 on Mon 18 Aug 2014 04:10 AM (UTC) Amended on Mon 18 Aug 2014 04:12 AM (UTC) by Nick Gammon
|
Message
| 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.
This is because the MUSHclient processing converts that to:
And then Lua string processing converts it to:
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. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
13,736 views.
It is now over 60 days since the last post. This thread is closed.
  Refresh page
top
Quick links:
MUSHclient.
MUSHclient help.
Forum shortcuts.
Posting templates.
Lua modules.
Lua documentation.
Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.