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
Ralph1971
Wanderer


Joined: 01 Mar 2008
Posts: 64

PostPosted: Fri Feb 18, 2011 4:25 pm   

#case vs #if
 
Would it be better to do multiple nested #if's, or #case?
#if (@adept="yes") {#if (@dispel="yes") {cast dispel} {cast spell} {#if (@brew="yes") {brew spell} {#if (@scribe="yes") {scribe spell}} {cast spell}
I'm sure I've gotten lost with the closing brackets, but you get the point...
or..
#if (@adept="yes") {#case @dispelstatus {cast dispel} {cast spell}} {#case @spellstatus {Brew spell} {scribe spell}}
spellstatus previously given a value of 1, 2, 3 etc earlier
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Fri Feb 18, 2011 5:46 pm   
 
in the case of a binary evaluation (ie, true/false), it doesn't matter. The coding advantage of #CASE versus #IF only comes into play when you have 3 or more outcomes from a single condition:

1)#CASE only evaluates the condition once

Code:
#variable count 4
#CASE @count {} {} {} {}


2)nested #IFs evaluate at least 3 times (given the example above)

Code:
#variable count 4
#IF (@count = 4) {
} {
  #if (@count = 3) {
  } {
    #if (@count = 2) {
  } {
  }
}
_________________
EDIT: I didn't like my old signature
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