Referring easily to an amount of money

I had started to write some regex to parse lines like ‘give $3 to scavenger’, ‘drop 5 bucks’, ‘give 30 dollars’, ‘eat $20.00’ so they’d all turn the money amount mentioned into one happy format (or in some cases, just the money thing in the player’s inventory) before going off to the appropriate action code. If the following code wasn’t just illegal, my regex would be trying to achieve the following in the majority of cases…

Before doing anything to (an amount of money) when the player carries the money:
if the player carries the money:
now noun is the money;
instead try the current action;

…and something more specific in only a few.

Then I got ideas from that topic of Amanda’s about the library book numbers, and thought maybe I could get Inform to recognise all these things for me.

e.g.
$1.99 specifies a dollar-amount

But once I have dollar-amounts in play, it seems I’d have to write a specific version of each action referring to the dollar-amount to achieve similar to what my regex was trying to do.

e.g.

Understand 'drop [dollar-amount]' as money-dropping.
Understand 'eat [dollar-amount]' as stupid-money-eating.

That seems worse than the regex.

I was wondering if there’s a way to use the non-regex approach that’s not as bad as that. Or if I should just do the regex.

-Wade

The player carries some money.
Understand "[dollar-amount]" as the money.
1 Like

Thanks much! I still haven’t got that idea of tokenising a single object into my head yet. This case will help.

To put the whole thing together to create a system where there are lots of ways to refer to the money, including just a raw number at times (no dollar sign), I did this:

player carries some money.

A monetary value is a kind of value.
$1.99 specifies a monetary value with parts dollars and cents (optional, preamble optional).
999 dollar specifies a monetary value with parts dollars.
999 dollars specifies a monetary value with parts dollars.
999 buck specifies a monetary value with parts dollars.
999 bucks specifies a monetary value with parts dollars.
999 money specifies a monetary value with parts dollars.
999 cash specifies a monetary value with parts dollars.

Understand "[number]" as the money when player carries money and there are no disambiguables.
[This means if numbered disambiguation choices is currently offering choices, they come first.]

Does the player mean doing something to the money:[General deprioritisation. Any time there's something else in the environment that can be referred to with just a number, we want that thing to take priority over the money if all the player did was mention a number without including a dollar sign, or a word like 'bucks']
	it is unlikely;

Does the player mean doing something when the money is the second noun:
	it is unlikely;

-Wade

Doh! This worked fine in isolation. Then I brought it back to my game where I rediscovered I strip periods from commands because chained commands can break things across mode changes under Unified Glulx Input. I think I’ll have to go some regex at least.

EDIT: Solved this by only accepting whole dollar amounts, and blocking any commands with a cents and dollars amount with a message telling you you don’t need cents.

-Wade