Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » zMUD General Discussion
Xozes
Beginner


Joined: 24 Dec 2000
Posts: 24

PostPosted: Thu Jan 31, 2002 5:59 am   

MUD spits out numbers with comma separators
 
I am on a MUD that gives numerical data with thousands separators (ex 1,230 gold on hand) is there an easy way to parse this correctly, and get the numbers right? so far, my script is only pickin up the very first set.. before the first separator.
Reply with quote
Charbal
GURU


Joined: 15 Jun 2001
Posts: 654
Location: USA

PostPosted: Thu Jan 31, 2002 7:36 am   
 
Whenever you want to convert the number, do something like %replace("%1",",","") instead of "%1". That will remove all commas. An example:

#TRIGGER {You need (*) exp to reach the next level.} {#var TNL %replace("%1",",","")}


 - Charbal
Reply with quote
LightBulb
MASTER


Joined: 28 Nov 2000
Posts: 4817
Location: USA

PostPosted: Thu Jan 31, 2002 7:10 pm   
 
I'd recommend using %x instead of *. There shouldn't be any spaces within a number. I'd also recommend using %number to ensure you get a number instead of a string.

#TR {(%x) gold on hand} {#VAR gold1 %number(%replace("%1",",",""))}

LightBulb
All scripts untested unless otherwise noted
Reply with quote
Charbal
GURU


Joined: 15 Jun 2001
Posts: 654
Location: USA

PostPosted: Fri Feb 01, 2002 12:24 pm   
 
quote:

I'd recommend using %x instead of *. There shouldn't be any spaces within a number. I'd also recommend using %number to ensure you get a number instead of a string.

#TR {(%x) gold on hand} {#VAR gold1 %number(%replace("%1",",",""))}



Or if we want to be even more picky:

#TR {[0-9,] gold on hand} {#VAR gold1 %number(%replace("%1",",",""))}

A less specific trigger can be (very, very marginally) faster than other, more specific triggers at times, provided the less specific doesn't generate false positives.

For example,
#trigger {^This is a %* blah blah blah$}
would probably be faster than
#trigger {^This is a {test|drill|whatever|blah|etcetera|telephone|octopus|radio|Santa|creme-filled donut|dinosaur|plumber|trail|pencil|PK|client|orange juice|........} blah blah blah$}

At some point, zMUD would spend more time figuring out if something wasn't in the list than applying a wildcard.

Sure, you may only get a millisecond (if that) but if you save a millisecond on 100 triggers, you'll have an extra 0.1 seconds to run away from a big guy with an axe :P

 - Charbal
Reply with quote
GaidinBDJ
Wanderer


Joined: 15 Nov 2002
Posts: 52
Location: Las Vegas, Nevada

PostPosted: Mon Sep 12, 2005 4:04 pm   
 
Ok, I'm trying

#trigger {You need (%x) more experience points to advance your level.} {#echo %replace(%1,",","")}

And it's just giving me the number up until the first comma

I.e.
Code:

You need 3,726,858 more experience points to advance your level.     
3
_________________
Barry
Gaidin @ 3k.org
Reply with quote
nexela
Wizard


Joined: 15 Jan 2002
Posts: 1644
Location: USA

PostPosted: Mon Sep 12, 2005 5:07 pm   
 
I think %n strips out the comma's but I don't have zmud in front of me to double check

#trigger {You need (%n) more experience points to advance your level.} {#ECHO %1}
_________________
Zmud Support Library
Zmud Knowledge Base
Reply with quote
Private
Adept


Joined: 10 Jan 2002
Posts: 264
Location: USA

PostPosted: Mon Sep 12, 2005 7:56 pm   
 
http://forums.zuggsoft.com/modules/mx_kb/kb.php?page=3&mode=doc&k=627
-->
%n match a number that starts with a + or - sign

should also note that it catches #'s with commas, but not numbers with a decimal in em (123.99)

Assuming it is on a line by itself.... (if not remove the ^ or $ as needed)
Code:

#trigger {^You need &tnl more experience points to advance your level.$} {tnl = %replace(@tnl,",","");#echo @tnl}


Code:

>#SHOW You need 123,456,789 more experience points to advance your level.
You need 123,456,789 more experience points to advance your level.
123456789


as a side note...
Code:

>#SHOW You need +123,456,789.012 more experience points to advance your level.
You need +123,456,789.012 more experience points to advance your level.
+123456789.012
Reply with quote
GaidinBDJ
Wanderer


Joined: 15 Nov 2002
Posts: 52
Location: Las Vegas, Nevada

PostPosted: Tue Sep 13, 2005 11:15 am   
 
It worked fine with "You need (%n) more experience" then "%replace(%1,",","").
_________________
Barry
Gaidin @ 3k.org
Reply with quote
GaidinBDJ
Wanderer


Joined: 15 Nov 2002
Posts: 52
Location: Las Vegas, Nevada

PostPosted: Tue Sep 13, 2005 1:10 pm   
 
I'm gonna use this thread to ask another question.

Does anybody know how to figure out a percentage? Like I have two values, current exp and the exp I need, is there any way to echo liek (35.34%) or something?
_________________
Barry
Gaidin @ 3k.org
Reply with quote
nexela
Wizard


Joined: 15 Jan 2002
Posts: 1644
Location: USA

PostPosted: Tue Sep 13, 2005 10:36 pm   
 
I belive that will be

#SAY %eval(%float(@currentXP)/@neededXP*100)

To only display the 2 decimal places

#SAY %format(2,%eval(%float(@currentXP)/@neededXP*100))
_________________
Zmud Support Library
Zmud Knowledge Base
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD 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