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


Joined: 23 Jan 2011
Posts: 20

PostPosted: Wed Aug 12, 2015 12:41 am   

Formatting some Math...
 
I've been reading through prior examples but only found some for Zmud, which doesn't seem to work right in Cmud.. any help with the following would be appreciated!

Goal: When Characters is less than Total Online, color that line, and append the the difference between the two (_on the same line_)

What I've got it doing so far:

# Characters. # Total Online. <<--This shows up as I want it to.
Unseen: # <<-- This shows up in cyan, on its own line

What I want it to do:
# Characters. # Total Online. Unseen:# <<<--This value should ONLY appear if the Total Online is greater than Characters


This is what I did:

<trigger priority="12540" id="1254">
<pattern>(%a) characters. Total online: (%a).</pattern>
<value>#IF ((%1) &lt; (%2)) {#CW "white,mxpgray"}
#MATH unseen %2-%1
#ECHO Unseen: @unseen
</value>
</trigger>

Any suggestions on how to wrangle what I've got, into what I'm hoping for?

With thanks,

Cordir


Last edited by Cordir on Wed Aug 12, 2015 12:47 am; edited 1 time in total
Reply with quote
shalimar
GURU


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

PostPosted: Wed Aug 12, 2015 12:46 am   
 
I would suggest %d over %a, but that shouldn't affect things...
the #MATH command is the issue here, sort of
all mathamatical expressions need to be wrapped in parenthesis, so:

#MATH unseen (%2-%1)
or
unseen=(%2-%1)

although, since you have no real need to store the value, i wouldnt bother saving it to a variable at all

#SAYADD { (%2-%1)}

that will append the value to the line
_________________
Discord: Shalimarwildcat
Reply with quote
Cordir
Beginner


Joined: 23 Jan 2011
Posts: 20

PostPosted: Wed Aug 12, 2015 12:50 am   
 
Forgive me, I'm very much a newbie and am not entirely following you.

This:
<trigger priority="12540" id="1254">
<pattern>(%d) characters. Total online: (%d).</pattern>
<value>#IF ((%1) &lt; (%2)) {#CW "white,mxpgray"} #SAYADD { (%2-%1)}
</value>
</trigger>

is resulting in this:
5 characters. Total online: 5.
ERROR: Trigger "(%d) characters. Total online: (%d)." fired but did not compile
Reply with quote
shalimar
GURU


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

PostPosted: Wed Aug 12, 2015 12:52 am   
 
wrap the xml in code tags to preserve spacing and the greater than symbols.
you need a semicolon between the two commands.
_________________
Discord: Shalimarwildcat
Reply with quote
Cordir
Beginner


Joined: 23 Jan 2011
Posts: 20

PostPosted: Wed Aug 12, 2015 1:03 am   
 
Embarassed "Code tags" ?
I couldn't find anything in the help files to explain what that is, precisely...

Again, very very VERY much a newbie when it comes to code type things.
Reply with quote
shalimar
GURU


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

PostPosted: Wed Aug 12, 2015 1:08 am   
 
the code tags are BBC code, to make things look proper on the forum.

Code:
<trigger priority="12540" id="1254">
<pattern>(%d) characters. Total online: (%d).</pattern>
<value>#IF ((%1) < (%2)) {#CW "white,mxpgray"} #SAYADD { (%2-%1)}
</value>
</trigger>


should be

Code:
<trigger priority="12540" id="1254">
<pattern>(%d) characters. Total online: (%d).</pattern>
<value>#IF ((%1) < (%2)) {#CW "white,mxpgray"}
#SAYADD { (%2-%1)}
</value>
</trigger>
_________________
Discord: Shalimarwildcat
Reply with quote
Cordir
Beginner


Joined: 23 Jan 2011
Posts: 20

PostPosted: Wed Aug 12, 2015 1:14 am   
 
When I use that, zmud is complaining about the < symbol and replacing it with " &lt; " and is not displaying the unseen # .
Reply with quote
shalimar
GURU


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

PostPosted: Wed Aug 12, 2015 1:32 am   
 
If all else fails, delete that trigger and enter this one on the command line.
It's the exact same trigger, just not in XML format.

Code:
#TR {(%d) characters. Total online: (%d).} {#IF (%1<%2) {#CW "white,mxpgray";#SAYADD { (%2-%1)}}}


Actually, this fixes a mistake i had put in the previous versions.
_________________
Discord: Shalimarwildcat
Reply with quote
Cordir
Beginner


Joined: 23 Jan 2011
Posts: 20

PostPosted: Wed Aug 12, 2015 3:06 am   
 
With that, I'm now getting this:

1 character. Total online: 4.(4-1)

It's not doing the math. :(


PS: I deeply appreciate the help! Thank you!
Reply with quote
shalimar
GURU


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

PostPosted: Wed Aug 12, 2015 3:11 am   
 
Hmmm... that should work...
Wait, did you say zMUD? this is the CMUD folder.
_________________
Discord: Shalimarwildcat
Reply with quote
Cordir
Beginner


Joined: 23 Jan 2011
Posts: 20

PostPosted: Wed Aug 12, 2015 3:13 am   
 
nono. I'm using CMUD (Cmud 3.34). I was only able to find references to math stuff in the ZMud forums :)


Last edited by Cordir on Wed Aug 12, 2015 3:50 am; edited 1 time in total
Reply with quote
Cordir
Beginner


Joined: 23 Jan 2011
Posts: 20

PostPosted: Wed Aug 12, 2015 3:31 am   
 
Here's what it looks like. (I had to add a small tweek because sometimes it's Characters and sometimes it's Character, depending on the # online.)

http://postimg.org/image/klck8aurn/
Reply with quote
shalimar
GURU


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

PostPosted: Wed Aug 12, 2015 4:03 am   
 
In that case, try this version:

Code:
#TR {(%d) character{s|}. Total online: (%d).} {#IF (%1<%2) {#CW "white,mxpgray";$temp=(%2-%1);#SAYADD {  $temp}}}
_________________
Discord: Shalimarwildcat
Reply with quote
shalimar
GURU


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

PostPosted: Wed Aug 12, 2015 4:53 am   
 
Code:
[code]P.S. this is how you would wrap your code for the forums.[/code]

_________________
Discord: Shalimarwildcat
Reply with quote
Cordir
Beginner


Joined: 23 Jan 2011
Posts: 20

PostPosted: Wed Aug 12, 2015 4:54 am   
 
HUZZAH!!
That worked!
Thank you so much for your help! :)
Reply with quote
shalimar
GURU


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

PostPosted: Wed Aug 12, 2015 5:07 am   
 
Glad that worked for you.
Still had to use a variable in the end, but $temp is a local variable, so it gets discarded after it is used and not left cluttering up your settings.
Don't forget to delete @unseen!
_________________
Discord: Shalimarwildcat
Reply with quote
Cordir
Beginner


Joined: 23 Jan 2011
Posts: 20

PostPosted: Wed Aug 12, 2015 5:22 am   
 
One last question, I PROMISE... :D
Is there a way to color format the output we've created, so that it matches the rest of the highlighting/color scheme? (Ie, so it's all that white lettering on gray background?)
Reply with quote
shalimar
GURU


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

PostPosted: Wed Aug 12, 2015 9:01 am   
 
Just add some MXP color tags:

Code:
#SAYADD {<color white mxpgray>  $temp</color>}


or better still, just reverse the #SAYADD and the #COLOR commands

#CW will color just the pattern
#CO will color the entire line
_________________
Discord: Shalimarwildcat
Reply with quote
Cordir
Beginner


Joined: 23 Jan 2011
Posts: 20

PostPosted: Wed Aug 12, 2015 9:31 am   
 
I've tried the above, and got this:
ERROR: Trigger "(%d) character{s|}. Total online: (%d)." fired but did not compile

I've also tried:
#IF (%1<%2) {#CW "white,mxpgray";$temp=(%2-%1);#SAYADD #CW "white,mxpgray"{ $temp}
Reply with quote
shalimar
GURU


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

PostPosted: Wed Aug 12, 2015 9:39 am   
 
Code:
#TR {(%d) character{s|}. Total online: (%d).} {#IF (%1<%2) {$temp=(%2-%1);#SAYADD {  $temp};#CO "white,mxpgray"}}

_________________
Discord: Shalimarwildcat
Reply with quote
Cordir
Beginner


Joined: 23 Jan 2011
Posts: 20

PostPosted: Wed Aug 12, 2015 9:59 am   
 
YAY!!!
That's it! :)

Many thanks, Oh Guru!
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