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
Sogdog
Newbie


Joined: 11 Dec 2007
Posts: 8

PostPosted: Mon Feb 02, 2009 8:20 am   

help with #IF
 
Hello all,

I know this is basic basic stuff, so sorry for that.
I did have a look for the answer myself, but the Zmud help files are a little thin on the usage of #if commands.

#if (@var1=0 AND @var2=0) {action1}
#if (@var1=1 OR @var2=1) {action2}
#if (@var1=1 AND @var2=1) {action3}

So as you can see I have two variables and three possible outcomes. As you can guess, what I have doesn't work. I'm assuming from my very limited knowledge there needs to be some brackets in there, but I don't have a clue where they go.

A bit of help to get me started would be much appreciated.

ps (It is just my assumption that the OR operator can be used, I haven't found any documentation on that either)
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4686
Location: Pensacola, FL, USA

PostPosted: Mon Feb 02, 2009 10:09 am   
 
The syntax you use in those examples looks spot on.
Perhaps you can show us the part you having trouble with?
_________________
Discord: Shalimarwildcat
Reply with quote
Sogdog
Newbie


Joined: 11 Dec 2007
Posts: 8

PostPosted: Mon Feb 02, 2009 10:23 am   
 
Thank you, your reassurances made me go back and check everything....and take out the spelling mistake.

Everything works fine now. Cheers muchly!!
Reply with quote
Sogdog
Newbie


Joined: 11 Dec 2007
Posts: 8

PostPosted: Mon Feb 02, 2009 12:34 pm   
 
But what I didn't see coming was when the third #IF statement is true, then the second #IF statement must be true as well, and both actions 2 and 3 will fire.

Back to that board with drawings on it...heh
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Mon Feb 02, 2009 3:22 pm   
 
Yes... logical OR isn't like the word "or" you use in conversation. "You can have cake or pie" implies that only one is true, but logical or means one or the other or both. There's a separate operation for what you're looking for, called XOR, but I'm not sure that that's supported in zScript the same way that AND and OR are. It's better just to use a logic tree for this:

Code:
#if (@var1=0) {
  #if (@var2=0) {action1} {action2}
} {
  #if (@var2=0) {acton2} {action3}
}
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
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