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: Fri Oct 08, 2004 4:48 pm   

Tough #if statement
 
Does anyone know how/why the script below works?

#CLASS {toughif}
#ALIAS test {#if %1 <@truebranch> <@falsebranch>}
#VAR truebranch {#echo "This branch is the:"
#echo "True Branch"}
#VAR falsebranch {#echo "This branch is the:"
#echo "False Branch"}
#CLASS 0

The syntax checker complains, but I decided I was skilled enough to ignore it Mr. Green. Is this syntax supported though or is it just luck that it works?

Edit: Test it with: "test 1" and "test 0"
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Fri Oct 08, 2004 10:23 pm   
 
First your #VAR assignments result in the variables containing "#echo This branch is the:;#ECHO Whichever Branch".

The %1 is subject to early expansion. It is limited to a single word or will contain its own delimeters. While it is best to put the () around the expression parameter the whole parameter is sent for evaluation.

The #IF takes 2 or 3 parameters. The <> classes as a delimeter (undocumented). So everything is technically seperated and correctly parsed as the desired parameters for #IF.

Finally the <@whicheverbranch> is passed whole to the parser. It now sees the <> as an expansion indicator and preforms unlimited expansion. This proccess strips the quotes of the variable and allows the parser to preform execution of the contained script.

The syntax itself "sloppy", it doesn't really fall into either a supported or unsupported category. I would personally call it unsupported since I think Zugg would never document any of those shortcuts. I know I wouldn't. In fact I have been removing most references to the <> expansion shortcut from the help, there weren't many to begin with.
_________________
The only good questions are the ones we have never answered before.
Search the Forums
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