Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
bishopnenar
Beginner


Joined: 20 Mar 2007
Posts: 27

PostPosted: Wed May 02, 2007 5:09 pm   

[1.32] Local variable and #SWITCH
 
Code:

$type = %1
$amount = %2
$person = %3
$pot = @pot
$price = 0
#SWITCH ($type = "health" || "mana") {$price = 75} ($type = "frost" || "epidermal") {$price = 150}


For some reason when $type is equal to frost, the $price is still equalling 75. Don't understand why this switch statement is not working.
I can post the full code if need, doubt it will be though. but at the end i I have

Code:

say (($amount)*($price)) is the cost, please


Any thoughts?
Reply with quote
Fang Xianfu
GURU


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

PostPosted: Wed May 02, 2007 5:46 pm   
 
You need to have a complete expression after the OR. "$type = "health" || "mana"" means "If $type=health is true or if mana is true". "mana" on its own will always evaluate to true and so the #switch will never get past that. Use "$type="health" || $type="mana".

As an aside, you probably don't need the innermost sets of brackets in your say part, and you can directly assign the %n variables to local variables by putting them in the Params box of the package editor. If you put "$type,$amount,$person" in the Params box you can do away with the first three lines.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
bishopnenar
Beginner


Joined: 20 Mar 2007
Posts: 27

PostPosted: Wed May 02, 2007 6:31 pm   
 
So by putting $localvar_whatever in the params box of an alias, elimantes the need to do what I did defining them?

Does this "speed" anything up? or have and other benifit other then having less lines to read through?

And thanks for point this out, still getting use to the $local variables.
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Thu May 03, 2007 5:06 pm   
 
Yes, it also speeds things up.
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD 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