|
thegto Beginner
Joined: 12 Jun 2007 Posts: 20
|
|
|
|
chaossdragon Apprentice
Joined: 09 Apr 2008 Posts: 168
|
Posted: Fri Nov 24, 2023 4:24 am |
#MATH is depreciated you can just use () to eval
try
$AABB = (100/50)
#SHOW $AABB |
|
|
|
Pauley Beginner
Joined: 17 May 2024 Posts: 17
|
Posted: 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.. |
|
|
|
mikeC130 Apprentice
Joined: 03 Jul 2006 Posts: 110
|
Posted: 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. |
|
|
|
Pauley Beginner
Joined: 17 May 2024 Posts: 17
|
Posted: 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 |
|
|
|
Pauley Beginner
Joined: 17 May 2024 Posts: 17
|
Posted: 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 |
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4715 Location: Pensacola, FL, USA
|
Posted: 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 |
|
|
|
Pauley Beginner
Joined: 17 May 2024 Posts: 17
|
Posted: 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) |
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4715 Location: Pensacola, FL, USA
|
Posted: 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 |
|
|
|
Pauley Beginner
Joined: 17 May 2024 Posts: 17
|
Posted: 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 |
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4715 Location: Pensacola, FL, USA
|
Posted: Mon Jul 08, 2024 11:37 pm |
There is a link to all the wildcard characters in #HELP #TRIGGER
|
|
_________________ Discord: Shalimarwildcat |
|
|
|
sosofa Newbie
Joined: 09 Nov 2024 Posts: 2 Location: Phoenix
|
Posted: 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.
|
|
|
|
chris123zugg Apprentice
Joined: 23 Aug 2013 Posts: 194
|
Posted: 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. |
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4715 Location: Pensacola, FL, USA
|
Posted: 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 |
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4715 Location: Pensacola, FL, USA
|
Posted: 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 |
|
|
|
chris123zugg Apprentice
Joined: 23 Aug 2013 Posts: 194
|
Posted: 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. |
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4715 Location: Pensacola, FL, USA
|
Posted: 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 |
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4715 Location: Pensacola, FL, USA
|
Posted: 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 |
|
|
|
chris123zugg Apprentice
Joined: 23 Aug 2013 Posts: 194
|
Posted: Sun Dec 29, 2024 12:32 am |
oh lol.. whelp if ya know ya know.. thanks again:)
|
|
|
|
chris123zugg Apprentice
Joined: 23 Aug 2013 Posts: 194
|
Posted: 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 |
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4715 Location: Pensacola, FL, USA
|
Posted: 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 |
|
|
|
|
|