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
Latent
Apprentice


Joined: 19 Aug 2002
Posts: 120
Location: USA

PostPosted: Wed Feb 19, 2003 8:43 pm   

help with #IF
 
is there any way to write an IF statement for something like #IF (%1 == blank) {then do something} I want to write a statement where if there is no %1 then do something... the reason for this is because i wrote an alias with a lot of IFs... perhaps there is a better way, here is the alias...
Name: Who
Value:
#IF (%1 == fam) {~who dechaoton}
#IF (%1 == enemy) {~who takhisis kirjolith}
#IF (%1 == group) {~who 205 205}
#IF (%1 == bud) {~who bud}
#IF (%1 == lov) {~who lov}
#IF (%1 == lovi) {~who lovi}
#IF (%1 == ally) {~who ally}
#IF (%1 == avatar) {~who avatar}
#IF (%1 == imm) {~who imm}
#IF (%1 == all) {~who}
#IF (%1 == seeking) {~who seeking}


the highlighted statement is the one i want to make if %1 is blank then ~who... but maybe there is a better way to make the whole alias?
The bolded statements are there because if I type nothing in, the who alias does nothing, so I have to put in anything that I might type in as an IF statement to do the same thing...
Reply with quote
TonDiening
GURU


Joined: 26 Jul 2001
Posts: 1958
Location: Canada

PostPosted: Wed Feb 19, 2003 9:01 pm   
 
Make a check with %numParam() to see if you have none.

#IF (%numParam() = 0) {#ECHO Syntax~:%tab who name%cr%tab who name name%cr%tab who level1 level2%cr%tab who etc..}

So to answer your question, the following should work:
#IF (%numParam() = 0) {~who}
Ton Diening
Reply with quote
wilh
Wanderer


Joined: 08 Feb 2001
Posts: 89
Location: USA

PostPosted: Wed Feb 19, 2003 9:09 pm   
 
Another solution that might have broader uses is the use of quotes:

#IF ("%1"=="") {...}

Happy coding. :)

Wil

Wil Hunt
Reply with quote
wilh
Wanderer


Joined: 08 Feb 2001
Posts: 89
Location: USA

PostPosted: Wed Feb 19, 2003 9:48 pm   
 
For Ton's response, the system function
%numparam()
will return 0 when there is no first parameter. Thus if you want to take action when there is no first paramter, the command
#IF (%numparam()==0) {doYourThingHere}
will accomplish this.

For my code, I use variable expansion. If there is no %1, then "%1" expands to simply "", thus
#IF ("%1"=="") {doYourThingHere}
gets the job done similarly.

Does that help? If not, please clarify what exactly is not clear.

Happy coding!

Wil

Wil Hunt
Reply with quote
Latent
Apprentice


Joined: 19 Aug 2002
Posts: 120
Location: USA

PostPosted: Wed Feb 19, 2003 10:05 pm   
 
thanks it worked
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Thu Feb 20, 2003 12:17 am   
 
quote:

Another solution that might have broader uses is the use of quotes:

#IF ("%1"=="") {...}

Happy coding. :)

Wil

Wil Hunt



Actually, I think trying to evaluate a parameter this way that isn't passed just causes the true code to fire (it's always one or the other). To check the value of %1, you either use %numparam() or specifically test for null-value using %null(). Most of the time I use %null(), since most of the aliases/functions I use tend to have a variable number of parameters or parameters for which %null is one of the options available.

li'l shmoe of Dragon's Gate MUD
Reply with quote
Emit
Magician


Joined: 24 Feb 2001
Posts: 342
Location: USA

PostPosted: Thu Feb 20, 2003 12:37 am   
 
even though it seems like you fixed your problem, i'd like to suggest an atlernative to having 11 #if checks:

#case (%ismember(%1, {fam|enemy|group})) {
~who dechaoton} {
~who takhisis kirjolith} {
~who 205 205} {
~who %1}

since there are only 3 cases where you want to change the argument, this checks for those three aguments, and changes them for those cases only. In any other case the argument will be sent to the mud appended to the who command as is.

--------

moon.icebound.net:9000
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