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


Joined: 09 Feb 2002
Posts: 39
Location: USA

PostPosted: Sat Feb 09, 2002 6:41 pm   

Multiple #if
 
OK got a scenerio with multiple possibilities. I'd like to runa a multiple if statement

lets say there are 4 if staements I'd like, if first one is true, I want the macro stopped at that point, and nothing done.

example

I hit heal macro
but if my health is full, nothing happens
if my health loss is less than 100 one action
if loss between 100 and 500 anouther action
if loss greater than 500 anouther action all together

BTW I have @myhealth (current health) and @basehealth (max health) variable set

Dazed glazed and having fun
Reply with quote
Kru
Beginner


Joined: 14 Nov 2001
Posts: 28

PostPosted: Sat Feb 09, 2002 7:33 pm   
 
Here is the colorful way that I would do it.

#ALIAS healme {#CASE (((@baseHealth-@myHealth)>0 and (@baseHealth-@myHealth)<100) OR ((@baseHealth-@myHealth)>100 and (@baseHealth-@myHealth)<500) OR ((@baseHealth-@myHealth)>500)) {doLessThan100Action} {doBetween100&500Action} {doGreaterThan500Action}}

(edit: I forgot the trailing }, its fixed now)
Reply with quote
Berion
Newbie


Joined: 10 Nov 2001
Posts: 8
Location: Norway

PostPosted: Sat Feb 09, 2002 8:04 pm   
 
Oh, I see you got the variables straight, i wish i read this before replying to your other post :p

This should work:

#IF (@myhealth=@basehealth) {#ECHO You are already healed!}
#IF (@myhealth<=@basehealth-1 & @myhealth>=@basehealth-100) {#ECHO 1 - 100}
#IF (@myhealth<=@basehealth-101 & @myhealth>=@basehealth-500) {#ECHO 101 - 500}
#IF (@myhealth<=@basehealth-501) {#ECHO More than 501}

Change the #echo's whith whatever command you want to happen.


-Berion
Reply with quote
Troubadour
GURU


Joined: 14 Oct 2000
Posts: 556
Location: USA

PostPosted: Sat Feb 09, 2002 9:39 pm   
 
First off, Kru's use of the #CASE command is incorrect; don't use that. The syntax for #CASE is:

#CASE number {command1} {command2} {command3} {etc}

The phrase (((@baseHealth-@myHealth)>0 and (@baseHealth-@myHealth)<100) OR ((@baseHealth-@myHealth)>100 and (@baseHealth-@myHealth)<500) OR ((@baseHealth-@myHealth)>500)) will not result in a number. (Well, maybe a 1 or 0, if it's interpreted as an expression.) Either way, the desired results of 1, 2, or 3 cannot be achieved.

Berion's example is good and straightforward.

Another way of doing it would be to nest the #IF statements:

#IF (@basehealth-@myhealth > 500) {action for loss >500} {#IF (@basehealth-@myhealth >100) {action for 100 < loss < 499} {#IF (@basehealth - @myhealth > 0) {action for 0 < loss < 99} {#NOOP}}}

Troubadour
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