While I know it's possible, I'm at a loss as to how approach the following problem. In this MUD you can count coins in <container> and it'll return "This is a pile of various types of coins, including ten copper shindigs, one gold boondoggle, one silver fart, nine copper troubles, and four silver cantaloupes."
Thanks to the help files, we know that shindigs are worth 1 each, boondoggles are worth 625 each, farts are worth 125 each, troubles are worth 5 each, and cantaloupes are worth 25 each.
How would we create a script that did the math and echo'd the actual value back to you?
Count Money
Re: Count Money
Hi!
So, I'm using code from viewtopic.php?t=22617 to do the number word to number conversion in the attached package. If you import it, the supplied example line comes out looking like this:
To summarize what I did:
I used the first part of the example line, "This is a pile of various types of coins, including" as a begin of line substring trigger. This trigger has the following in the code block, to reset the value to 0 since we're about to add it all up:
The code for the shindigs looks like this:
With the code block:
So, I'm using code from viewtopic.php?t=22617 to do the number word to number conversion in the attached package. If you import it, the supplied example line comes out looking like this:
To summarize what I did:
I used the first part of the example line, "This is a pile of various types of coins, including" as a begin of line substring trigger. This trigger has the following in the code block, to reset the value to 0 since we're about to add it all up:
I then made child triggers for each type of currency as a perl regex trigger, the example pattern for shindigs being: "(.*) copper shindigs"
The code for the shindigs looks like this:
Finally, beneath the perl regex triggers for the currency types, I made a substring trigger matching a single period: "."
With the code block:
And the coin_value definition is in a script, and looks like this:
- Attachments
-
- coincounter.mpackage
- (1.75 KiB) Downloaded 519 times
Re: Count Money
Nice! Works really well. I think it might have a problem with hyphenated money (I forgot to mention things like fourty-seven), but it should be easy enough to modify if so. Thank you!
Re: Count Money
Yeah, I don't believe the code I took from the other forum post used hyphenates, but that's where I would look to make your edits. If I get time later tonight I might try to tackle it.
ETA: if you capture the value as a hyphenate, say "forty-seven", you can use the following to change it to "forty seven"
ETA: if you capture the value as a hyphenate, say "forty-seven", you can use the following to change it to "forty seven"
Re: Count Money
It looks like the calculation in the example is incorrect, but I'm not sure why. It came up as $9115 when it should be $895. Any suggestions?
Re: Count Money
hmm, might help to use parantheses to ensure order of operations. I used "value = value + coins * coin_value.shindigs" and it might be more accurate to use "value = value + (coins * coin_value.shindigs)"
Will take a look later to see if that's it.
Will take a look later to see if that's it.
Re: Count Money
My triggers were off, I have attached a better, more accurate version that comes up with 905 (did you forget the 10 copper shindigs to get 895 maybe?) and matches my math. Thanks for catching that.
- Attachments
-
- cointcoins.mpackage
- (1.77 KiB) Downloaded 517 times
Re: Count Money
Almost perfect! I tested with various combinations using feedTriggers() with no problems.
There's one issue when the text comes from the mud though. The mud will show something like:
"This is a pile of various types of coins, including ten copper shindigs, one gold
boondoggle, one silver fart, nine copper troubles, and four silver cantaloupes."
Everything will be counted except the boondoggle, since it's split across a line break. Since you can hold many combinations of coins, it might break after a quantity, metal, or type of coin.
Looking around for similar problems people have had, maybe this is fixed with some sort of stayOpen?
There's one issue when the text comes from the mud though. The mud will show something like:
"This is a pile of various types of coins, including ten copper shindigs, one gold
boondoggle, one silver fart, nine copper troubles, and four silver cantaloupes."
Everything will be counted except the boondoggle, since it's split across a line break. Since you can hold many combinations of coins, it might break after a quantity, metal, or type of coin.
Looking around for similar problems people have had, maybe this is fixed with some sort of stayOpen?
Re: Count Money
This is easiest and best fixed by asking the MUD not to wrap the lines for you, and getting Mudlet to wrap them instead - this way your triggers get 1 easy line to work with. Can you turn line wrapping off in your game?
Re: Count Money
I asked, but there isn't a way to turn off the mud's wrap.