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


Joined: 20 Sep 2005
Posts: 3

PostPosted: Tue Sep 20, 2005 7:20 pm   

IF/ELSEIF/ELSE Statements in Zmud
 
Hey everyone. Im writing a pretty complex script, and i'm nearly done with it. Sadly, the last part requires me to check to see if 2 variables are in 3 states (10, 01, 11 as an example). Err, needless to say, I need something of an IF/ELSEIF statement for Zmud. Ive combed the helps, and cant find anything. Only thing i can find is the IF statement, but i need an ELSEIF as well =(
This possible in a single alias?
Or will i end up having to write a series of aliases chaining together constiting of if statements?
Reply with quote
Seyen
Beginner


Joined: 31 Aug 2005
Posts: 15

PostPosted: Tue Sep 20, 2005 7:32 pm   
 
Er... ELSEIF? Is that like #IF {condition} {do if true} {else do another IF}? Then why can't you just do it like i just said? Meaning,
Code:
#IF {} {} {#IF{} {} {}}
Reply with quote
billaben
Wanderer


Joined: 02 Sep 2005
Posts: 60

PostPosted: Tue Sep 20, 2005 7:33 pm   
 
That can all be built with what exists. Here is a quick arbitrary example I slapped out with the buit in zmud editor. Pretty print works well for churning out readable code. That should give you what you need for any complex If structures.

You also should check out the referance manual posted online here and study up on conditionals as well. Everything you need should be there.

Incidentally, if you have an if tree in mind. you will probably want a Priority on that block of code as well

Code:
#PRIORITY {
  #IF (@Condition=1) {
    #NOOP Then
    #NOOP
    } {
    #NOOP Else
    NOOP
    #IF (@AnotherCondition=1) {
      #NOOP Else IF Then
      #NOOP
      } {
      #NOOP Else IF Else
      NOOP
      }
    }
  }
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Tue Sep 20, 2005 8:44 pm   
 
#CASE is probably easier:

#case %ismember(@var1,"10|01|11") {
#NOOP for readability
#case %ismember(@var2,"10|01|11") {} {} {}
} {
#NOOP for readability
#case %ismember(@var2,"10|01|11") {} {} {}
} {#NOOP for readability
#case %ismember(@var2,"10|01|11") {} {} {}
}

Depending on your exact application, you might even be able to get away with using this:

#case %ismember(@var1,"10|01|11") {} {} {}
#case %ismember(@var2,"10|01|11") {} {} {}
_________________
EDIT: I didn't like my old signature
Reply with quote
Quantafel
Newbie


Joined: 20 Sep 2005
Posts: 3

PostPosted: Tue Sep 20, 2005 10:12 pm   
 
Ok im confused by most of this.. This is what i want to do..


if ((@buy1 > 1) && (@buy2 > 1))
{
long_mixed
}
else if ((@buy1 > 1 && (@buy2 == -1))
{
long_buy
}
else if (( @buy1 == -1 *&& (@buy2 > 1))
{
long_sell
}
else
{
long_error
}

I need something like that for this to work correctly.. =)
Reply with quote
billaben
Wanderer


Joined: 02 Sep 2005
Posts: 60

PostPosted: Tue Sep 20, 2005 10:34 pm   
 
What's hard to understand?

Note, you will still need a trigger wrapped around this so you can execute this block of code at the appropriate times.

Code:
#PRIORITY {
  #IF ((@buy1>1)&(@Buy2>1)) {
    #WIN test {long_mixed}
    #NOOP
    } {
    #IF ((@Buy1>1)&(@Buy2=-1)) {
      #WIN test {long_buy}
      #NOOP
      } {
      #IF ((@Buy=-1)&(Buy2>1)) {
        #WIN test {long_sell}
        #NOOP
        } {
        #WIN test {long_error}
        #NOOP
        }
      }
    }
  }
Reply with quote
Quantafel
Newbie


Joined: 20 Sep 2005
Posts: 3

PostPosted: Tue Sep 20, 2005 10:48 pm   
 
Ahhhh, Thanks Billaben! =) that worked. I was confused because I kept getting negitives on #if statements with 2 or more conditions for some odd reason. (C programming comming out, = being assign, == being equals and a few too many spaces for it to work ;) Ended up with, works flawlessly. (Was confusing because ive been working on this damnable script for 3 days now, and this last part got me stuck for 12 hours ;)
Appreciate it =)

Code:

#IF ((@buy1>1)&(@Buy2>1)) {
  #echo Long_mixed
  #NOOP
  } {
  #IF ((@Buy1>1)&(@Buy2=-1)) {
    #echo long_buy
    #NOOP
    } {
    #IF ((@Buy1=-1)&(@Buy2>1)) {
      #echo long_sell
      #NOOP
      } {
      #echo long_error
      #NOOP
      }
    }
  }
[/code]
Reply with quote
billaben
Wanderer


Joined: 02 Sep 2005
Posts: 60

PostPosted: Wed Sep 21, 2005 3:28 am   
 
No problem. Syntax in zMud can be rather tricky. I reccomend using the editor included with zMud and tagging pretty print regularly. it's good at catching syntax errors for ya.
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