Page 1 of 1
alias problem ^wc(.+)?$
Posted: Mon Apr 27, 2009 2:44 pm
by Caled
Code: Select all
Alias pattern: ^wc(.+)?$
Script:
if matches[2] == nil then
send( "clan 2 who" )
else
send( "clan 2 tell " .. matches[2] )
end
I tried the above with "" instead of nil, and also with matches[1] just in case aliases are different to triggers. The alias just won't fire. It is supposed to allow me to:
"wc" to check my clan who
"wc <text here>" to speak on the clan channel.
I use this check for nil arguments/parameters a lot - for most aliases in fact.
Example in zscript:
#alias {cc} {#IF(%null(%1)) {#2 claw @target} {#2 claw %1}}
In Mudlet I would assume:
Code: Select all
Alias Pattern: ^cc(?:\s)?(\w+)?$
or: ^cc\s?(\w+)?$
Script:
if matches[2] == nil then
send( "claw " .. target)
send( "claw " .. target)
else
send( "claw " .. matches[2])
send( "claw " .. matches[2])
end
Please help!
Re: alias problem ^wc(.+)?$
Posted: Tue Apr 28, 2009 4:13 am
by Ramiel
Alias pattern: ^wc(.+)?$
You seem to be missing a space between the wc and the capture.
Re: alias problem ^wc(.+)?$
Posted: Tue Apr 28, 2009 4:45 am
by Caled
I figure the capture group will match the space.
But I did try these two alternate patterns as well. None work and i don't see why not.
Re: alias problem ^wc(.+)?$
Posted: Tue Apr 28, 2009 9:24 am
by Heiko
Here you go:
pattern: ^wc\s?(.+)?$
Code: Select all
if matches[2] == nil then
echo("caled alias called without arguments\n");
else
echo("caled alias called cap group<"..matches[2]..">\n");
end
patterns like
^wc *(.+)?$ or
^wc *(.*) would also work.
info on regex quantifiers:
http://www.regular-expressions.info/repeat.html
Some background info:
As soon as the alias pattern matches the alias unit will intercept and block the command and issue the clear text substitution if you specified any and run the script. If there is no substitution specified and the script doesn't send a command, the user command will simply be consumed and ignored.
If the script causes a Lua error for some reason the script will stop execution as soon as the error happens, but run again the next time you enter the command.
In your case:
Code: Select all
echo("caled alias called without arguments\n");
echo("caled alias called cap group<"..matches[2]..">\n");
would print the first echo if there are no parameters to "wc" and both echos if there are parameters. If there is no further parameters to "wc" the script execution will cause an error on the second echo, as matches[2] is undefined, and stop execution, thus only printing the first echo.
Re: alias problem ^wc(.+)?$
Posted: Wed Nov 11, 2009 11:59 am
by Heiko
Empty capture groups
If capture group x is empty matches[x]="" (note that it is *NOT* = nil as nil means that the table index x is not defined)
Consequently, you could write:
Code: Select all
Alias Pattern: ^cc(?:\s)?(\w+)?$
or: ^cc\s?(\w+)?$
Script:
if matches[2] == "" then
send( "claw " .. target)
send( "claw " .. target)
else
send( "claw " .. matches[2])
send( "claw " .. matches[2])
end