|
Rorso Wizard
Joined: 14 Oct 2000 Posts: 1368
|
Posted: Sat Apr 17, 2004 10:10 am
An alias parameter issue |
I have detected something odd with the alias parameters. It seems as if the %1 syntax doesn't work properly.
Example:
#ALIAS test {#echo %1}
test a b c
-> a b c
But in my opinion it should have displayed 'a' only as explained in the zMUD help file:
quote: Aliases can also contain Parameters. Parameters are the text following the shortcut. For example, if you enter fs foo bar, fs is the alias shortcut, foo is the first parameter, bar is the second parameter. Parameters are assigned to specific numeric variables %1 through %99. In the previous case, %1 would contain foo, and %2 would contain bar. You can use these parameters in the alias itself.
Does anyone know what's wrong? |
|
|
|
Vijilante SubAdmin
Joined: 18 Nov 2001 Posts: 5182
|
Posted: Sat Apr 17, 2004 1:24 pm |
I don't believe it is mentioned in the help for aliases, but the effect you noticed is explained in the help for %param.
Syntax: %param(n)
return the nth parameter passed to an alias.
Example:
#ALIAS testParam {#LOOP %numparam() {#SAY %param(%i)};#NOOP}
testParam With a rubber duck, one's never alone.
displays:
With
a
rubber
duck,
one's
never
alone.
NOTE: The #NOOP is used to take care of the 'unused' parameters. Parameters are only flagged 'used' if accessed with the temporary variables %1, %2, etc. |
|
|
|
LightBulb MASTER
Joined: 28 Nov 2000 Posts: 4817 Location: USA
|
Posted: Sat Apr 17, 2004 4:13 pm |
Certainly it's mentioned under #ALIAS.
"Any text following the aliasname that is not used as a parameter is appended to the results of the alias expansion."
If you only want the first parameter used, it's up to you to discard everything after it.
#AL test {#ECHO %1;#NOOP}
Of course, most people know what they designed their aliases to do and don't supply excess text in the first place. |
|
|
|
Rorso Wizard
Joined: 14 Oct 2000 Posts: 1368
|
Posted: Sat Apr 17, 2004 9:09 pm |
quote: Originally posted by LightBulb
Certainly it's mentioned under #ALIAS.
"Any text following the aliasname that is not used as a parameter is appended to the results of the alias expansion."
If you only want the first parameter used, it's up to you to discard everything after it.
#AL test {#ECHO %1;#NOOP}
Of course, most people know what they designed their aliases to do and don't supply excess text in the first place.
Ah I feel so stupid =) Thanks for clarifying this. |
|
|
|
LightBulb MASTER
Joined: 28 Nov 2000 Posts: 4817 Location: USA
|
Posted: Sun Apr 18, 2004 5:58 am |
[:o)] Heh.
Yes, I'm sure you also know what you design aliases for. In particular, you designed this alias to illustrate what you considered to be a problem and it does so perfectly. I just don't agree that it's a problem.
Appending the leftover text is the correct behavior. I have written many aliases which rely on this behavior to save me the trouble of explicitly allowing for a flexible number of parameters. |
|
|
|
|
|