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


Joined: 10 Jul 2007
Posts: 47

PostPosted: Tue Apr 19, 2011 10:00 pm   

#ADD problem and Totaling Variables
 
I'm trying to use #ADD, and cant figure out why its not working (as I've used this with variables many times before).

So for this example we will have variables AA, BB, CC, DD

First of all, when I'm using the #ADD function if AA was already equal to 6 and I wanted to add 1 to now equal 7... #ADD AA 1 but instead of the output being 7 I get an output of 61, then if I add 1 more to it the output then becomes 611.. etc etc.

Next, I've tried to add the variables AA, BB, CC to equal DD.
I've tried %eval(AA+BB+CC) that didn't work. Then I tried to nest it with %eval(%eval(AA+BB)+CC)) and that didnt work. Then I tried #VAR EE AA+BB and then DD=CC+EE. Its not working at all. What it does is squishes all the numbers together as explained in the #ADD example (IE: AA=1 BB=2 CC=3 then output of and of the equations to mean AA+BB+CC= 123 as opposed to the correct answer of 6)

Also, if this matters at all - I'm trying to put these variables in the status bar. The variables themselves are working just not when I try to add/subtract/total.
Using CMUD v3.33
Reply with quote
Zugg
MASTER


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

PostPosted: Tue Apr 19, 2011 10:24 pm   
 
If you get the output "61" then CMUD thinks that your AA variable is a literal string value instead of a number. In CMUD, "adding" for strings is the same as concating.

You shouldn't need %eval in CMUD.

What you need to do it look at how the variables are getting set. If you do:

AA = "6"

then that sets it as a string variable. If you do:

AA = 6

then that sets it as a numeric variable. To *force* a string to become a number, use the %int function.

In CMUD, use normal expressions and assignment rather than using the old zMUD #ADD and #MATH commands. For example, this works fine:
Code:
AA=1
BB=2
CC=3
Result = (@AA+@BB+@CC)
#SHOW @Result
#SHOW (@AA+@BB+@CC)

Putting () parenthesis around an expression will evaluate it (like %eval) but will be quicker than %eval. The above script will display 6 correctly twice.

So try something like:
Code:
AA = (@AA + 1)

and see how that works. And make sure you are not setting the variables as literal strings somewhere.
Reply with quote
mandy
Novice


Joined: 10 Jul 2007
Posts: 47

PostPosted: Wed Apr 20, 2011 12:09 am   
 
Okay changed all the variables from "auto type" to "integer" and that worked. Thanks much!

Still had to use %eval for the status bar, but I was unable to use it as a totaling variable but just as the equation. Using just the parenthesis just returned the output (value of AA + value of BB + value of CC)

Is there a way that I can set the value of a variable to an equation? I want the value of DD to ALWAY be equal to AA+BB+CC. I tried changing DD back to an auto type variable and putting the equation in the value field but I failed again.
Reply with quote
Zugg
MASTER


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

PostPosted: Wed Apr 20, 2011 4:18 pm   
 
Quote:
Is there a way that I can set the value of a variable to an equation?

Yes, you want a #FUNCTION for that:
Code:
#FUNCTION DD {#RETURN (@AA+@BB+@CC)}

For the status bar, yes you still need to use %eval there because a status bar item is expected to be a string value. So to embed a calculation, %eval is still needed there.

You shouldn't need to change the variables from "auto type". As long as they are not "string" variables then auto-type should still work for the calculations.
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