Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ MUSHclient
➜ General
➜ Variable trigger matching (or creating a rewrite rule)
Variable trigger matching (or creating a rewrite rule)
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Tharius
(29 posts) Bio
|
Date
| Sun 01 Dec 2013 03:41 AM (UTC) |
Message
| I'm looking to create a trigger to match my prompt but rather than hardcode the match pattern I'd like to use the mud output of the prompt change command to rewrite the trigger.
eg (apologies ... I'm used to zmud but looking to get a lot better at mush's scrpiting system):
#trig {matchMyPromptRegEx} {assignVariables}
#trig {matchMultiLinePromptChangeText} {#untrig matchMyPromptRegEx;#trig {newMatchMyPromptRegEx} {assignVariables}}
In essence either I'd like to have a trigger that tests for a match against a variable in which would be stored a regex or a method to delete/modify an existing trigger from within the lua scripting (sort of akin to the way you can use javascript to rewrite a drop down box in html).
The idea is that if I change my prompt I don't have to go hand editing my scripts, that the change will be registered.
Thanks
| Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #1 on Sun 01 Dec 2013 04:43 AM (UTC) |
Message
| Yes, the match text can itself be a variable, eg.
@my_prompt
If you are matching on a regular expression you would need to be cautious about auto-generating this variable, as some characters have special meaning inside a regexp, however in principle you can certainly do that.
Quote:
... or a method to delete/modify an existing trigger from within the lua scripting ...
That is achievable too, but using the variable is probably simpler.
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Tharius
(29 posts) Bio
|
Date
| Reply #2 on Sun 01 Dec 2013 12:10 PM (UTC) |
Message
|
Nick Gammon said:
Yes, the match text can itself be a variable, eg.
@my_prompt
If you are matching on a regular expression you would need to be cautious about auto-generating this variable, as some characters have special meaning inside a regexp, however in principle you can certainly do that.
Nick,
Thanks for the speedy reply ... and the good news. Matching against a variable seems the easiest, I'll go ahead and play with it and see what comes of it.
I had realized the warning about the reg ex special characters but if I can get the variable approach working perhaps I don't need to be so general after all and can do something much simpler.
Steve | Top |
|
Posted by
| Tharius
(29 posts) Bio
|
Date
| Reply #3 on Fri 13 Dec 2013 05:07 PM (UTC) |
Message
| Nick,
As you anticipated there is some difficulty with getting the matching regex from inside the variable to work.
When I match from the variable but exclude the regex expressions (eg I match the literal text) the technique works perfectly.
So here's a version of it, I have also tried \w, (\w) \(\w\) and double slash combinations etc so normal string escaping doesn't seem to be the solution (I simplified it from a larger expression to get as simple an example as possible)
It "seems" that although the string parses in ok, that the regular expression evaluation does not happen after variable expansion.
This is precisely what I need to complete this small prompt writing script and would open up a world of possibilities.
<variables>
<variable name="testvar">A little \\w string</variable>
</variables>
<triggers>
<trigger
enabled="y"
expand_variables="y"
keep_evaluating="y"
match="@testvar"
regexp="y"
send_to="2"
sequence="100"
>
<send>saw testvar</send>
</trigger>
</triggers>
| Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #4 on Fri 13 Dec 2013 08:22 PM (UTC) Amended on Fri 13 Dec 2013 08:23 PM (UTC) by Nick Gammon
|
Message
| Are you trying to match some word? In that case the testvar needs to be:
<variables>
<variable name="testvar">A little (\w+) string</variable>
</variables>
And the trigger needs a "!" after the "@" to tell it not to convert the regular expression, like this:
<triggers>
<trigger
custom_colour="2"
enabled="y"
expand_variables="y"
keep_evaluating="y"
match="@!testvar"
regexp="y"
send_to="2"
sequence="100"
>
<send>saw testvar, got word: %1</send>
</trigger>
</triggers>
With those changes, it works:
A little fish string
saw testvar, got word: fish
(MUD output in bold). |
- 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.
18,701 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top