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: 4715
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: 4715
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: 4715
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: 2
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
chris123zugg
Apprentice


Joined: 23 Aug 2013
Posts: 194

PostPosted: Fri Dec 27, 2024 8:51 pm   
 
HP: (1530/1548) SP: (514/514) NE: (488/885) SO: (660/660) GXP: (LR: 62/TNL: 641.983)
bladesinger.gxplr=%9 <--- which is the LR:62

i have a total GXP earned elsewhere, the variable for it is bladesinger.tgxp

i want to ADD bladesinger.gxplr to bladesinger.tgxp
when i use #add bladesinger.tgxp @bladesinger.gxplr it literally adds the value of 62 at the end instead of adding the numbers together.

spoiler: i feel like ive had this problem in several places and youve already told me... so i apologize ahead of time, i looked in my history and dont see it.
Reply with quote
shalimar
GURU


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

PostPosted: Sat Dec 28, 2024 4:32 pm   
 
You are showing me the raw prompt, I assume you are having trouble constructing the pattern?

You need to quote out the literal parenthesis with a tilde, and then use parenthesis and wildcards to capture various parts into the anonymous variables before they have a value.

#TR {HP: ~((%d)/(%d)~) SP: ~((%d)/(%d)~) NE: ~((%d)/(%d)~) SO: ~((%d)/(%d)~) GXP: ~(LR: (%d)/TNL: (%d.%d)~)} {do stuff}

Looking back over this...
Sounds like your variable is of the wrong type, or is being assumed to be a string for some reason (like a trailing space from using the wrong wildcard or not using %trim).
Thus, your attempt to use the #ADD command is acting more like a %concat.
The error mentioned in #HELP #ADD but not specified.

The solution for that is simple enough.
* Tighten up your patterns to use the right wildcards
* Make use of typing functions when making variable declarations (%int, %string, %float)
_________________
Discord: Shalimarwildcat
Reply with quote
shalimar
GURU


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

PostPosted: Sat Dec 28, 2024 4:39 pm   
 
$total=%int(%db(@bladesinger, tgxp))
$current=%int(%db(@bladesinger, gxplr))
$total=($total+$current)
#ADDKEY bladesinger tgxp %int($total)

The third %int there is likely unnecessary, but code doesn't care how pedantic I get to ensure things.
_________________
Discord: Shalimarwildcat
Reply with quote
chris123zugg
Apprentice


Joined: 23 Aug 2013
Posts: 194

PostPosted: Sat Dec 28, 2024 5:19 pm   
 
$total=%int(%db(@bladesinger, tgxp))
$current=%int(%db(@bladesinger, gxplr))
$total=($total+$current)
#ADDKEY bladesinger tgxp %int($total)
#print $total

Yours is just stripping the known variable and replacing it with 0 then starting to count the last input from %9
below is the total gxp available capture. so the bladesinger.tgxp should remain filled from the capture below and then add per rd the script you added

<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
<trigger priority="121810" copy="yes">
<pattern>Total GXP~:%s([0-9,])</pattern>
<value>//Total GXP: 72,316
bladesinger.tgxp=%1
</value>
</trigger>
</cmud>

is the base capture.. its already an integer with no floating point.
Reply with quote
shalimar
GURU


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

PostPosted: Sun Dec 29, 2024 12:16 am   
 
It should be returning the integer value of x, if you are getting 0 its because your variable evaluates to 0

Try:

bladesinger.tgxp=%int(%replace(%1, ","))
_________________
Discord: Shalimarwildcat
Reply with quote
shalimar
GURU


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

PostPosted: Sun Dec 29, 2024 12:19 am   
 
#SAY %int("72,316")
0

#SAY %int(72,316)
72

It's an issue of garbage in, garbage out.
I suppose it should know how to handle commas, but it sees those as a separator between parameters.
_________________
Discord: Shalimarwildcat
Reply with quote
chris123zugg
Apprentice


Joined: 23 Aug 2013
Posts: 194

PostPosted: Sun Dec 29, 2024 12:32 am   
 
oh lol.. whelp if ya know ya know.. thanks again:)
Reply with quote
chris123zugg
Apprentice


Joined: 23 Aug 2013
Posts: 194

PostPosted: Sun Dec 29, 2024 1:37 am   
 
okie i added to the tgxp capture
bladesinger.tgxp=%int(%replace(%1, ","))



and used your other script
$total=%int(%db(@bladesinger, tgxp))
$current=%int(%db(@bladesinger, gxplr))
$total=($total+$current)
#ADDKEY bladesinger tgxp %int($total)
#print $total

which now workis flawlessly, wanna run me step by step how that changed it???
the only difference that i can see is that you forced the variable @bladesinger.tgxp to be an interger before it was then changed in the round to round adding to the bladesinger.tgxp
Reply with quote
shalimar
GURU


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

PostPosted: Sun Dec 29, 2024 2:05 am   
 
Not a problem!
It makes sense if you think about it.
Commas aren't actually a part of the number, it's just grammatical indexing to make it easier for humans to read.
_________________
Discord: Shalimarwildcat
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