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
Opoponax
Beginner


Joined: 16 Sep 2008
Posts: 20

PostPosted: Tue Sep 30, 2008 4:27 pm   

Variable generating a true/false.
 
Just wondering how to make the following work.

Code:
#var test1 "%if(1 = 2, 1, 0)"
#IF (@test1) {#echo True} {#echo False}


In zMUD it would evaluate to a "False" but in CMUD it generates a "True."
If I imbed the code in an alias it works in CMUD no problem, I'd just like to have it in a handy place for easy editing rather then multiple copies spread throughout the package.

I'm thinking/hoping it's just a syntax issue on my part, because similar aliases work, it's just the ones that require <>= that seem to have problems.

Thank you!
Reply with quote
Zugg
MASTER


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

PostPosted: Tue Sep 30, 2008 5:03 pm   
 
CMUD does not evaluate any variables or functions within the "" quotes. So your #IF statement is always true because @test1 contains a string value that is not blank. You should do just:
Code:
#var test1 %if(1 = 2, 1, 0)
#IF (@test1) {#echo True} {#echo False}

if you want CMUD to evaluate the %if function during the variable assignment. If you are trying to create a function that will evaluate arguments later, then you can do something like this:
Code:
#FUNCTION test1 {#RETURN %if(%1 = %2, 1, 0)}
#IF (@test1(1,2)) {#echo True} {#echo False}
Reply with quote
Opoponax
Beginner


Joined: 16 Sep 2008
Posts: 20

PostPosted: Tue Sep 30, 2008 5:20 pm   
 
It was the evaluate later I was looking for. I'd looked at using a function, but saw it wanted something to execute rather then just returning an evaluation. Overlooked the #return.

Thank you very much.
Reply with quote
Zugg
MASTER


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

PostPosted: Tue Sep 30, 2008 7:22 pm   
 
Yeah, to get something like the old "inline" functions in CMUD, you use #VARFUNC. Like this:
Code:
#VARFUNC test1 {%if(%1 = %2, 1, 0)}
#IF (@test1(1,2)) {#echo True} {#echo False}

See the Changes for zMUD Users topic: http://www.zuggsoft.com/kb/cmud_changes_varfunc
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