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
danr62
Beginner


Joined: 17 May 2003
Posts: 20
Location: USA

PostPosted: Fri Jun 27, 2003 12:56 am   

What's wrong with the following code?
 
Ok, I have a bit of code that I can't figure out, here's what I have

#alias vin {
#if (%1 = "") {
put %numitems( @vials) vial in pack
}
#if ((%1 != "") & (%1 != ((health | mana | levitation | immunity | venom | speed | caloric | restoration | empty)))) {#echo ERROR}

If I type vin by itself, both statements come out true...
Reply with quote
danr62
Beginner


Joined: 17 May 2003
Posts: 20
Location: USA

PostPosted: Fri Jun 27, 2003 1:06 am   
 
Also if I type vin health, the second #if statement comes out true, if I type in "vin (health | mana | levitation | immunity | venom | speed | caloric | restoration | empty)", then it comes out false, is there any way to check it against all those without typing a seperate #if statement for each?
Reply with quote
Lalaynya
Wanderer


Joined: 23 Aug 2002
Posts: 96

PostPosted: Fri Jun 27, 2003 3:24 am   
 
Look up the %ismember() function in the help file!
Reply with quote
Emit
Magician


Joined: 24 Feb 2001
Posts: 342
Location: USA

PostPosted: Fri Jun 27, 2003 3:46 am   
 
wierd. try using %null and instead of the second check, just use the else clause of the first check:

#alias vin {
#if (%null(%1)) {
put %numitems( @vials) vial in pack
} {
#if (!%ismember(%1, "health|mana|levitation|immunity|venom|speed|caloric|restoration|empty")) {
#echo ERROR
}
}
}
Reply with quote
LightBulb
MASTER


Joined: 28 Nov 2000
Posts: 4817
Location: USA

PostPosted: Fri Jun 27, 2003 12:04 pm   
 
quote:
If I type vin by itself, both statements come out true...

If you type vin by itself, there is no %1, which is equivalent to a null string, and therefore the first statement is true. Since a null string is not equal to (health | mana | levitation | immunity | venom | speed | caloric | restoration | empty), the second statement is also true. This is expected behavior.

(health | mana | levitation | immunity | venom | speed | caloric | restoration | empty) can't be used in an not-equals statement this way. It's the same as (health OR mana OR levitation OR immunity OR venom OR speed OR caloric OR restoration OR empty). This is a boolean OR statement, and will be equal to 1 if any of its elements are true. They are all true (nonzero), so it's always equal to 1. The inequality will be true (generate the ERROR message) for anything except "vin 1".

Emit already gave you a fix but I thought an explanation might also help.
Reply with quote
Emit
Magician


Joined: 24 Feb 2001
Posts: 342
Location: USA

PostPosted: Fri Jun 27, 2003 5:22 pm   
 
the second #if should have failed if he didn't pass an argument, he AND ed it with %1 != ""
thats the part that was failing Smile
Reply with quote
LightBulb
MASTER


Joined: 28 Nov 2000
Posts: 4817
Location: USA

PostPosted: Fri Jun 27, 2003 5:43 pm   
 
Yep, I missed that. That, of course, is the problem with using null arguments, the results are unpredictable. The correct test is
#alias vin {
#if (%numparam() = 0) {
put %numitems( @vials) vial in pack
} {
#if (!%ismember(%1, "health|mana|levitation|immunity|venom|speed|caloric|restoration|empty")) {
#echo ERROR
}
}
}
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