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


Joined: 12 Jun 2007
Posts: 20

PostPosted: Thu Nov 23, 2023 11:54 pm   

How does #MATH works?
 
Code:

#MATH AABB {100/50}; #SHOW @AABB


Here what I got from #SHOW
Code:

100/50


Shouldn't I get result 2 ?

I followed this help file
http://forums.zuggsoft.com/modules/mx_kb/kb.php?page=3&mode=doc&k=220

CMUD Pro 3.34
Reply with quote
chaossdragon
Apprentice


Joined: 09 Apr 2008
Posts: 168

PostPosted: Fri Nov 24, 2023 4:24 am   
 
#MATH is depreciated you can just use () to eval

try

$AABB = (100/50)

#SHOW $AABB
Reply with quote
Pauley
Beginner


Joined: 17 May 2024
Posts: 17

PostPosted: Fri Jul 05, 2024 10:34 am   
 
I cannot get #MATH to work, curious as to what I'm doing wrong.

I have a spell's duration which is 2 times your current wisdom + 200 (so the total = X seconds)

I made a trigger to capture my wisdom in the @WIS variable
then I made a IWDUR variable (the spells duration) which contains this:

#MATH (200+@WIS+@WIS)

Let us say for this example that my wisdom is 150, so that the WIS variable is 150 - the math becomes 200+150+150=500 seconds duration

However, when I type #SHOW @IWDUR, the output in the mud is this:

"#MATH (200+150 +150 )"

So it is not doing math on it at all..
Reply with quote
mikeC130
Apprentice


Joined: 03 Jul 2006
Posts: 110

PostPosted: Fri Jul 05, 2024 10:37 pm   
 
No, #MATH doesn't do math in cMud - it isn't actually a command any more, so the parser is treating it as just a string of text. It is expanding your variables, but not doing anything with them as the expression is considered a line of text.

Get rid of the #MATH command and just leave the expression (200+@WIS+@WIS) and it should evaluate it.

ETA: It is still in the list of commands, so it *SHOULD* work, but it doesn't seem to in your example and isn't needed in any case, so just leave it off.
Reply with quote
Pauley
Beginner


Joined: 17 May 2024
Posts: 17

PostPosted: Sun Jul 07, 2024 7:50 am   
 
mikeC130 wrote:
No, #MATH doesn't do math in cMud - it isn't actually a command any more, so the parser is treating it as just a string of text. It is expanding your variables, but not doing anything with them as the expression is considered a line of text.

Get rid of the #MATH command and just leave the expression (200+@WIS+@WIS) and it should evaluate it.

ETA: It is still in the list of commands, so it *SHOULD* work, but it doesn't seem to in your example and isn't needed in any case, so just leave it off.


Trying this with #ECHO or #SHOW @IWDUR (expecting the final result "500" to be displayed on screen) I find that it still yields "200 150 150" in the mud window

The variable IWDUR contains only this phrase "(200+@WIS+@WIS)" and for some reason refuses to process it in any other way than as just plain text to be displayed in the mud window

Quite possibly i have implemented this in the wrong way

Edit1:

If i type "#SHOW (2+2)" it displays "4"
If I type "#SHOW (200+150+150)" it displays "500"

but here comes the snag, when i type "#SHOW (200+@WIS+@WIS)" it displays "200 150 150"

Edit2:

"#MATH TEST (@WIS+@WIS)" yields "150 150" when I type"#SHOW @TEST" while:
"#MATH TEST {@WIS+@WIS}" yields "150 + 150" when I type"#SHOW @TEST"

How confusing that it doesn't want to compute it, it just displays the numbers as they are

Edit3:

Also trying "#MATH TEST (@WIS*2)" yields "0" with "#SHOW @TEST" - so it's clearly doing something to it, but it fumbles and returns 0
Reply with quote
Pauley
Beginner


Joined: 17 May 2024
Posts: 17

PostPosted: Sun Jul 07, 2024 4:54 pm   
 
Big oooof

The problem was that the trigger capturing my wisdom also captured one blankspace :3

Works as it should now

Edit:
Changed a %1 to "%s(%n)%s" in the capture trigger to avoid getting the blankspace in the variable, this fixed the problem
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4691
Location: Pensacola, FL, USA

PostPosted: Sun Jul 07, 2024 11:43 pm   
 
The #MATH command has been officially deprecated and made redundant, any equation in parentheses will try to evaluate itself, use nested parenthesis when you need to force order of operations.

using %1 as a wildcard is bad form to begin with, that is a captured variable reference
if you just want a numeric value use the %d wildcard, %n is specifically for signed +/- numbers.

P.S. %trim will remove trailing spaces from both sides
_________________
Discord: Shalimarwildcat
Reply with quote
Pauley
Beginner


Joined: 17 May 2024
Posts: 17

PostPosted: Mon Jul 08, 2024 5:38 am   
 
shalimar wrote:
The #MATH command has been officially deprecated and made redundant, any equation in parentheses will try to evaluate itself, use nested parenthesis when you need to force order of operations.

using %1 as a wildcard is bad form to begin with, that is a captured variable reference
if you just want a numeric value use the %d wildcard, %n is specifically for signed +/- numbers.

P.S. %trim will remove trailing spaces from both sides


Thank you for the advice, I'm struggling a bit with navigating all the different stuff and what would be best to use (and there's so much to sift through)
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4691
Location: Pensacola, FL, USA

PostPosted: Mon Jul 08, 2024 10:10 am   
 
General speaking, there is no real 'best' way to do things, just a bunch of tools in the toolbox

The #HELP command can be used with any command or function to read the help files

#HELP #MATH
#HELP %clip
_________________
Discord: Shalimarwildcat
Reply with quote
Pauley
Beginner


Joined: 17 May 2024
Posts: 17

PostPosted: Mon Jul 08, 2024 1:22 pm   
 
shalimar wrote:
General speaking, there is no real 'best' way to do things, just a bunch of tools in the toolbox

The #HELP command can be used with any command or function to read the help files

#HELP #MATH
#HELP %clip


Oh wow, that's incredibly helpful, I spent hours yesterday looking through pages full of commands and all kinds of stuff just trying to find a list of %d, %n, %1, etc to see all my options and what their definitions are
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4691
Location: Pensacola, FL, USA

PostPosted: Mon Jul 08, 2024 11:37 pm   
 
There is a link to all the wildcard characters in #HELP #TRIGGER
_________________
Discord: Shalimarwildcat
Reply with quote
sosofa
Newbie


Joined: 09 Nov 2024
Posts: 1
Location: Phoenix

PostPosted: Sat Nov 09, 2024 8:51 am   
 
This sounds amazing as I found it very much useful and informative to be honest. Also, I have gone through this post which definitely helped me out a lot as a new member I am looking forward for more such discussions.
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