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
Ghedemonas
Novice


Joined: 15 Aug 2007
Posts: 39

PostPosted: Wed Jan 09, 2008 9:57 pm   

Numbers
 
Hello again,
My mud (Realms of the Dragon) has the following output for counting potions, where I would like to store the word-numbers (like Ten or Twenty four) into a number variable (10, 24) for each type of potions.
Any hints on how to do this? I thought about making some kind of DB-query, but it sound complicated to make and to match ...
Cheers and Thanks alot
Ghede

Here is a sample output:
count potions
You have a total of 34 potions in your direct inventory.
Ten Orange Potions
Twenty four Baneful Pink Potions
271 potions held inside of your Worn Backpack. (backpack 1)
Ten Yellow Potions
Nine Clear Potions
Nineteen Baneful Pink Potions
Twelve Red Potions
Two Baneful Yellow Potions
Eighty Potions of True Cure Water
Three Magenta Potions
Two Baneful Orange Potions
Twenty eight Cyan Potions
Forty eight Mana Potions
Forty five Baneful Red Potions
Seven Violet Potions
Six Vapor Form Potions

For a total of 305 potions in your inventory.
>
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Wed Jan 09, 2008 10:09 pm   
 
First topic in the Finished Scripts forum. Go go gadget Matt!

Damn, this is CMUD and not zMUD. I could've sworn I checked that. Anyway, check out Vijilante's toolbox in the package library - it's got functions that'll do that and back again, as well as a bunch of other stuff you probably won't need.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
Ghedemonas
Novice


Joined: 15 Aug 2007
Posts: 39

PostPosted: Sat Jan 19, 2008 1:49 am   
 
NP :) I downloaded the function now but -

if I enter #call @WordToNum(Ten) it does not return 10 ..
Same goes for #call @WordToNum("Ten")
I'd greatly appreciate your help here :)
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Sat Jan 19, 2008 4:14 am   
 
Use Vijilante's function from the package library (which was made for CMUD) and not the one I linked for zMUD. His function works fine.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
Ghedemonas
Novice


Joined: 15 Aug 2007
Posts: 39

PostPosted: Thu Apr 24, 2008 7:36 pm   
 
I adapted the MattLofton's Zmud Function to fit CMUD and added some things ...

Usage: @WordToNum(one thousand, two hundred and twenty one)

- It now can cope with figures that contain "," and "and"
- "no" is now counted as "0"
- it captures 2 numbers that seem not to have been captured before (e.g. one thousand one hundred)

#VARIABLE Ones {one|two|three|four|five|six|seven|eight|nine}

#VARIABLE Tens {twenty|thirty|forty|fifty|sixty|seventy|eighty|ninety}

#FUNCTION WordToNum {%case( %numwords( %replace( %replace( %replace( %1, ", ", " "), " and ", " "), "-", " ")), %case( %ismember( %1, "no|one|two|three|four|five|six|seven|eight|nine|ten|eleven|twelve|thirteen|fourteen|fifteen|sixteen|seventeen|eighteen|nineteen|twenty|thirty|forty|fifty|sixty|seventy|eighty|ninety"),0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,30,40,50,60,70,80,90), %eval( %if( %pos( "hundred", %1), %case( %ismember( %word( %replace( %replace( %replace( %1, ", ", " "), " and ", " "), "-", " "), 1), @ones),100,200,300,400,500,600,700,800,900), %if( %pos( "thousand", %1), %case( %ismember( %word( %replace( %replace( %replace( %1, ", ", " "), " and ", " "), "-", " "), 1), @ones),1000,2000,3000,4000,5000,6000,7000,8000,9000), %case( %ismember( %word( %replace( %replace( %replace( %1, ", ", " "), " and ", " "), "-", " "), 1), @tens),20,30,40,50,60,70,80,90) + %case( %ismember( %word( %replace( %replace( %replace( %1, ", ", " "), " and ", " "), "-", " "), 2), @ones),1,2,3,4,5,6,7,8,9)))), %eval( %if( %pos( "thousand", %1), %case( %ismember( %word( %replace( %replace( %replace( %1, ", ", " "), " and ", " "), "-", " "), 1), @ones),1000,2000,3000,4000,5000,6000,7000,8000,9000), %case( %ismember( %word( %replace( %replace( %replace( %1, ", ", " "), " and ", " "), "-", " "), 1), @ones),100,200,300,400,500,600,700,800,900)) + %case( %ismember( %word( %replace( %replace( %replace( %1, ", ", " "), " and ", " "), "-", " "), 3), "one|two|three|four|five|six|seven|eight|nine|ten|eleven|twelve|thirteen|fourteen|fifteen|sixteen|seventeen|eighteen|nineteen|twenty|thirty|forty|fifty|sixty|seventy|eighty|ninety"),1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,30,40,50,60,70,80,90)), %eval( %if( %pos( "thousand", %1), %case( %ismember( %word( %replace( %replace( %replace( %1, ", ", " "), " and ", " "), "-", " "), 1), @ones),1000,2000,3000,4000,5000,6000,7000,8000,9000), %case( %ismember( %word( %replace( %replace( %replace( %1, ", ", " "), " and ", " "), "-", " "), 1), @ones),100,200,300,400,500,600,700,800,900)) + %if( %ismember( %word( %replace( %replace( %replace( %1, ", ", " "), " and ", " "), "-", " "), 4), "hundred"), %case( %ismember( %word( %replace( %replace( %replace( %1, ", ", " "), " and ", " "), "-", " "), 3), @ones),100,200,300,400,500,600,700,800,900), %eval(%case( %ismember( %word( %replace( %replace( %replace( %1, ", ", " "), " and ", " "), "-", " "), 3), @tens),20,30,40,50,60,70,80,90) + %case( %ismember( %word( %replace( %replace( %replace( %1, ", ", " "), " and ", " "), "-", " "), 4), @ones),1,2,3,4,5,6,7,8,9)))), %eval( %case( %ismember( %word( %replace( %replace( %replace( %1, ", ", " "), " and ", " "), "-", " "), 1), @ones),1000,2000,3000,4000,5000,6000,7000,8000,9000) + %case( %ismember( %word( %replace( %replace( %replace( %1, ", ", " "), " and ", " "), "-", " "), 3), @ones),100,200,300,400,500,600,700,800,900) + %case( %ismember( %word( %replace( %replace( %replace( %1, ", ", " "), " and ", " "), "-", " "), 5), "one|two|three|four|five|six|seven|eight|nine|ten|eleven|twelve|thirteen|fourteen|fifteen|sixteen|seventeen|eighteen|nineteen|twenty|thirty|forty|fifty|sixty|seventy|eighty|ninety"),1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,30,40,50,60,70,80,90)), %eval( %case( %ismember( %word( %replace( %replace( %replace( %1, ", ", " "), "and ", ""), "-", " "), 1), @ones),1000,2000,3000,4000,5000,6000,7000,8000,9000) + %case( %ismember( %word( %replace( %replace( %replace( %1, ", ", " "), " and ", " "), "-", " "), 3), @ones),100,200,300,400,500,600,700,800,900) + %case( %ismember( %word( %replace( %replace( %replace( %1, ", ", " "), " and ", " "), "-", " "), 5), @tens),20,30,40,50,60,70,80,90) + %case( %ismember( %word( %replace( %replace( %replace( %1, ", ", " "), " and ", " "), "-", " "), 6), "one|two|three|four|five|six|seven|eight|nine|ten|eleven|twelve|thirteen|fourteen|fifteen|sixteen|seventeen|eighteen|nineteen|twenty|thirty|forty|fifty|sixty|seventy|eighty|ninety"),1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,30,40,50,60,70,80,90)))}
Reply with quote
Ghedemonas
Novice


Joined: 15 Aug 2007
Posts: 39

PostPosted: Fri Jun 20, 2008 10:57 pm   
 
It seems the usage in 2.27+ changed
from
@WordToNum(one thousand, two hundred and twenty one)
to
@WordToNum("one thousand, two hundred and twenty one")

I pinpointed the problem to the following part of the script (the one that deals with 2-letter numbers ... 21-99,100,1000,200,2000 etc

%eval( %if( %pos( "hundred", %1), %case( %ismember( %word( %replace( %replace( %replace( %1, ", ", " "), " and ", " "), "-", " "), 1), @ones),100,200,300,400,500,600,700,800,900), %if( %pos( "thousand", %1), %case( %ismember( %word( %replace( %replace( %replace( %1, ", ", " "), " and ", " "), "-", " "), 1), @ones),1000,2000,3000,4000,5000,6000,7000,8000,9000), %case( %ismember( %word( %replace( %replace( %replace( %1, ", ", " "), " and ", " "), "-", " "), 1), @tens),20,30,40,50,60,70,80,90) + %case( %ismember( %word( %replace( %replace( %replace( %1, ", ", " "), " and ", " "), "-", " "), 2), @ones),1,2,3,4,5,6,7,8,9))))

Try running the following test script:
#show TEST START;#show ONE LETTER;#show -1- @wordtonum("one");#show TWO LETTERS;#show -99-: @wordtonum("ninety nine") ;#show -100-: @wordtonum("one hundred") ;#show -1000-: @wordtonum("one thousand");#show THREE LETTERS;#show -1010- @wordtonum("one thousand ten") ;#show -110- @wordtonum("one hundred ten");#show FOUR LETTERS;#show -1099- @wordtonum("one thousand ninety nine") ;#show -1100- @wordtonum("one thousand one hundred") ;#show -199- @wordtonum("one hundred ninety nine") ;#show FIVE LETTERS;#show -1110- @wordtonum("one thousand one hundred ten") ;#show SIX LETTERS;#show -1199- @wordtonum("one thousand one hundred ninety nine");#show TESTEND

Does anyone have an idea how to fix that?
Reply with quote
Caled
Sorcerer


Joined: 21 Oct 2000
Posts: 821
Location: Australia

PostPosted: Mon Jun 23, 2008 5:43 am   
 
Actually, Fang, I think Vijilante's functions for this in his toolbox are unfinished.
@WordstoNumber(one) displays '1'
@WordstoNumber(twenty four) displays '0 twentyfour'
@WordstoNumber(twenty four) displays '24'
@wordstonumber(one thousand, two hundred and twenty-one) displays '0 onethousand'
_________________
Athlon 64 3200+
Win XP Pro x64
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Mon Jun 23, 2008 5:28 pm   
 
Keep in mind that whenever you want to preserve the spaces within a string and to use special characters, you should always enclose the string within quotes. In your example:

@WordToNum(one thousand, two hundred and twenty one)

you are actually passing "one thousand" to %1, and "two hundred and twenty one" as %2. In your second example, the entire string is passed to %1 since it properly has the quotes around the string. Maybe Vijilante's scripts have some tricks to deal with that, I don't know.
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Mon Jun 23, 2008 8:20 pm   
 
I never did update the script for the changes in %subregex. There is at least one reference in there that needs to be fixed, and probably I should rewrite the whole thing to take advantage of all the other replacements available. Zugg is correct in stating that quotes are needed, and it is not something I would really like trying to get around. I probably could, but that would just encourage shoddy scripts.
_________________
The only good questions are the ones we have never answered before.
Search the Forums
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