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
➜ Perlscript
➜ AddTrigger doesn't add when regexp
AddTrigger doesn't add when regexp
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Yasik
Ukraine (15 posts) Bio
|
Date
| Tue 05 Jul 2011 01:49 PM (UTC) |
Message
| Greetings!
I've been reading the Forum for 2 days as for now and I guess I was looking good and long enough to find an answer to my question if there's was one, but it seems like there isn't...
The alias (nothing much):
<aliases>
<alias
script="zzz"
match="re-ssk"
enabled="y"
send_to="12"
sequence="100"
>
</alias>
</aliases>
The script code (PerlScript):
sub zzz {
my ($thename, $theoutput, $wildcards) = @_;
my $z;
$z = $world->AddTrigger ("re__ssk", "You feel less protected.", "cast 'Stone Skin'", 1025, -1, 0, "", "");
$world->Note ($z);
};
The above does work. The below - doesn't.
sub zzz {
my ($thename, $theoutput, $wildcards) = @_;
my $z;
$z = $world->AddTrigger ("re__ssk", "^You feel less protected\.$", "cast 'Stone Skin'", 1057, -1, 0, "", "");
$world->Note ($z);
};
Flags: 1025 - replace exisiting with same name and enabled, 1057 - same as before + regexp.
Perl 5.14.1 build 1401.
The error mesassage:
Script error
World: SLOTH
Execution of line 1 column 0
Immediate execution
Compilation error
Error context in script:
1*: sub zzz {
2 : my ($thename, $theoutput, $wildcards) = @_;
3 : my $z;
4 : $z = $world->AddTrigger ("re__ssk", "^You feel less protected\.$", "cast 'Stone Skin'", 1057, -1, 0, "", "");
5 : $world->Note ($z);
Can post Debug ("summary") if needed.
How do I make this work? I'm totally confused. Thanks in advance. | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #1 on Tue 05 Jul 2011 09:33 PM (UTC) Amended on Tue 05 Jul 2011 09:34 PM (UTC) by Nick Gammon
|
Message
|
"^You feel less protected\.$"
My guess here is the backslash, which is one of the few things you changed. You put it there I presume so you would escape the period. But in PHP a backslash inside quotes would have another meaning, and it probably objects to backslash-dot.
Try two backslashes.
The message is "Compilation error" which means something to do with PHP syntax, not to do with how MUSHclient treats regular expressions. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Yasik
Ukraine (15 posts) Bio
|
Date
| Reply #2 on Wed 06 Jul 2011 04:31 PM (UTC) |
Message
| After few experiments, I have found out that an expression between two quotes is actually an regexp-in-regexp.
I should escape a dot, escape a slash escaping a dot and escape a slash escaping a slash escaping a dot. And escape an $ sign. No joking. The setup that actually worked as I want it to is as follow:
ALIAS:
<aliases>
<alias
script="zzz"
match="re-ssk"
enabled="y"
send_to="12"
sequence="100"
>
</alias>
</aliases>
SCRIPT:
sub zzz {
my $z;
$z = $world->AddTrigger ("re__ssk", "^You feel less protected\\\.\$", "cast 'Stone Skin'", 1057, -1, 0, "", "");
$world->Note ($z);
};
TRIGGER ADDED:
<triggers>
<trigger
enabled="y"
match="^You feel less protected\.$"
name="re__ssk"
regexp="y"
sequence="100"
variable="re__ssk"
>
<send>cast 'Stone Skin'</send>
</trigger>
</triggers>
Now it consist of "^", "\." and "$".
Thanks for leading me to the root of the problem :) | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #3 on Wed 06 Jul 2011 10:07 PM (UTC) |
Message
| Oh yeah I'd forgotten that the $ has meaning in PHP.
I'm a bit surprised about the 3rd backslash. You don't really have a regexp-in-regexp, you have a regexp inside a string. First you need to defeat PHP's treating of special character like backslashes and dollar signs, and then the rexexp matcher itself has to get \. in order to process that as a single dot (and not a "match-all" character). |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Yasik
Ukraine (15 posts) Bio
|
Date
| Reply #4 on Thu 07 Jul 2011 04:27 AM (UTC) |
Message
| I think its because we dont have to enter a regexp in the AddTrigger function as we would enter it in the Add Trigger dialogue menu, but instead we should enter a string that will be processed and the result of this processing will be entered in the Configuration->Triggers->Edit Trigger->Trigger box when the function launches.
This way, in order to have a \.$ we had to escape a backslash, a dot and a $ sign : \\\.\$
Still i dont get it why ^ without escaping is ok if it works that way. | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #5 on Thu 07 Jul 2011 05:21 AM (UTC) |
Message
| The ^ has no special meaning to PHP, so it didn't need to be escaped. Both $ and \ do.
As I recall, in PHP if you used single quotes you wouldn't have to escape the $. This is because inside double quotes something like "$foo" means "the contents of the variable "foo". |
- 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.
21,107 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top