Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » zMUD General Discussion
Rorso
Wizard


Joined: 14 Oct 2000
Posts: 1368

PostPosted: 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?
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: 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.
Reply with quote
LightBulb
MASTER


Joined: 28 Nov 2000
Posts: 4817
Location: USA

PostPosted: 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.
Reply with quote
Rorso
Wizard


Joined: 14 Oct 2000
Posts: 1368

PostPosted: 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.
Reply with quote
LightBulb
MASTER


Joined: 28 Nov 2000
Posts: 4817
Location: USA

PostPosted: 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.
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net