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
radboi22
Novice


Joined: 19 Jan 2008
Posts: 30

PostPosted: Wed Mar 25, 2009 4:09 pm   

#IF, How to match Two patterns before Returning True
 
Hi, I checked pattern matching and can't figure it out, Let's say i want to match two variables, Ex...
#IF (@VARIABLE1=1 AND @VARIABLE2=2) {COMMAND} {IFNOT COMMAND}

What do i use in place of AND, in order for this to work, THANKS =D
Reply with quote
ReedN
Wizard


Joined: 04 Jan 2006
Posts: 1279
Location: Portland, Oregon

PostPosted: Wed Mar 25, 2009 4:28 pm   
 
The word 'and' will work just fine:

$a = 1
$b = 2

#if ($a == 1 and $b == 2) {#print True} {#print False}
Reply with quote
radboi22
Novice


Joined: 19 Jan 2008
Posts: 30

PostPosted: Wed Mar 25, 2009 4:38 pm   
 
THANKS A BUNCH!
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Wed Mar 25, 2009 10:15 pm   
 
Surround your subconditions with parentheses. When I don't do stuff like this, I find that the result of one side will then be evaluated against half of the other side:

A = 1, B = 0

#if (A = 1 and B = 0) --> (A = 1 and 0) --> (A = 0) --> (0) --> Wrong! Not what I wanted!

#if ((A = 1) and (B = 0)) --> ((1) and (1)) = (1) --> Right!

Sometimes you won't need the parentheses, but I'm of the mind that keeping track of the when/when not like this is more trouble than simply always using parentheses.
_________________
EDIT: I didn't like my old signature
Reply with quote
Leitia
Adept


Joined: 04 May 2007
Posts: 292
Location: Boston

PostPosted: Sat Mar 28, 2009 12:29 pm   
 
I thought to mention a couple foibles since the op began with an inquiry that answered itself. Excuse the poetics.

String comparisons are case sensitive, but you can force your data into upper or lower case before the conditional. This happens with %ismember() too.

#IF (%lower(%1)="something" AND %lower(%2)="anotherthing")

Sometimes you don't have input or a null thing that fools the conditional by making ZMud look at the weighed function as plain text. I got CMud mainly to escape the evolution that created !%null(%1), but still have that digital pachyderm in reserve in case I find myself naming 'if nests' batgirl as I seriously need heroics.

ZMud autotypes variables, on my journey into the deep nests I found mathematics was not always what I expected and number 1 was greater then number 3. Somehow I created the numbers as text, and against that needed %number(@OhVariable).

Just thought to say that in comparisons functions can be cranky and like people seem to associate with their own kind, though I think MattLofton said that in a practical way.


Last edited by Leitia on Sun Mar 29, 2009 5:08 am; edited 1 time in total
Reply with quote
Leitia
Adept


Joined: 04 May 2007
Posts: 292
Location: Boston

PostPosted: Sat Mar 28, 2009 12:32 pm   
 
double post
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