# A problem with money

Hi everyone.

I am trying to implement a REALLY simple money/barter system in Inform 7. Basically I have an innkeeper who will only give you a key when you give him 5 coins (known as ‘firnlots’ in my game… an anagram of florints for anyone who’s interested).

So all I do at the moment is set up the definition of a ‘firnlot’ like so…

[code]A firnlot is a kind of thing.
The description of a firnlot is “A roughly circular coin that is the accepted currency in these parts.”.
Understand “Coin” or “Coins” or “Money” as firnlot.
Understand “give [things] to [someone]” as giving it to.
The block giving rule is not listed in any rulebook.

[Temp]
A bag is carried by the player.
40 firnlots are in the bag.
[/code]

So I don’t bother with giving them monetary value as such, there’s only one opportunity for such a transaction in my small game (it’s my first) so I don’t really need a full blown monetary system.

Now all I need to do is check when the innkeeper receives 5 coins and hey presto, he’ll give you the key…

[code]The innkeeper can be satisfied or unsatisfied.
The innkeeper is unsatisfied.

Before giving firnlots to the innkeeper:
if the innkeeper is satisfied, stop the action;

After giving firnlots to the innkeeper:
if the innkeeper is satisfied, stop the action;
if the innkeeper has 5 firnlots:
say “‘Very well then,’ says the innkeeper, ‘you can borrow my ladder but you had better bring it back in one piece. Here’s the key to remove the padlock.’”;
now the iron key is carried by the player;
now the innkeeper is satisfied.[/code]

This works fine, except for one thing… the output looks like this…

```>give 6 firnlots to the innkeeper firnlot: (first taking the firnlot) firnlot: (first taking the firnlot) firnlot: (first taking the firnlot) firnlot: (first taking the firnlot) firnlot: (first taking the firnlot) "Very well then," says the innkeeper, "you can borrow my ladder but you had better bring it back in one piece. Here's the key to remove the padlock." firnlot:```

(I deliberately gave him 6 firnlots to test what would happen)

Yuck!! How can I get rid of all those needless “firnlot: (first taking…” lines?
I’ve been trying to figure this out for hours but my head is spinning now.

Chris.

First suggestion: make money a variable instead of each coin being an object if you’re having that much currency in the game.

I can post more when not on my phone, but others will likely chime in.

Here you go, sorry I couldn’t do this on my phone earlier!

[spoiler][code]Cash is a number that varies. Cash is 40.

firnlots is a thing. The printed name is “[if cash is 1]a[otherwise]some[end if] firnlot[if cash is greater than 1]s[end if]”. The description is “You count your coins and determine you have [cash in words] of them.” Understand “cash/money/coin/coins/purse/firnlot” as firnlots.

When play begins:
if cash is greater than 0:
now the player holds firnlots.

Every turn when cash is greater than 0:
now the player holds firnlots.

Every turn when cash <= 0:
remove firnlots from play.

Inn is a room.

the Innkeeper is a man in Inn. “The innkeeper stares at you[if player does not hold iron key] unctiously as if he doesn’t believe you can afford a room[end if].” The description is “[if the player holds iron key]‘Enjoy your stay, Sir,’ the Innkeeper says patronisingly.[otherwise]The innkeeper makes it clear that a room costs five firnlots, and loitering is not allowed unless you’re going to BUY A ROOM.”

an iron key is held by innkeeper. Understand “room” and “room key” as iron key. Understand “rent [something]” as buying.

The block buying rule is not listed in the check buying rulebook.

if the noun is not iron key:

if the player holds iron key:

if cash is less than 5:
say “Alas, you cannot afford the five firnlots a room costs in swanky lodgings like this.”;
stop the action.

decrease cash by 5;
now the player carries iron key.

say “The Innkeeper is surprised that you’re not the nomadic wastrel he inferred you were, and hands over an iron key to a room in exchange for five firnlots.”

Before jumping:
if cash is greater than 1 :
say “You seem to have forgotten there are holes in your pockets and coins jingle as they bounce away in every direction.”;
change cash to 1;
rule succeeds;
if cash is 1 :
change cash to 0.

Test fail with “x innkeeper/i/x firnlots/jump/i/x innkeeper/buy room/i”[/code][/spoiler]

Forgot one part. If the player tries to drop money. Here you want to decide if you want to go the easy way and either not allow money to be dropped (with an instead rule), just make dropped money vanish (someone else will surely pick it up) or if you want to try and keep track of random dropped coins…which would be rather tedious. Perhaps you could just require the player will drop everything or nothing.

[code]moneypile is a number that varies.
some discarded coins is a thing. The description is “You see [moneypile in words] coin[if moneypile is greater than 1]s[end if] here.” Understand “coin/money/cash/firnlot/firnlots” as discarded coins.

say “You drop your coins here. Surely they will be safe.”;
change moneypile to 0 + cash;
change cash to 0;
move discarded coins to the location.

say “You grab the discarded money.”;
increase cash by moneypile;
if firnlots is off-stage:
now player carries firnlots.
[/code]
What this means is the pile of coins will remain, until the player gains and drops money again somewhere, else, in which case the first pile will vanish. Finders-Keepers!

Wow! Thanks so much for the help! This is way more than I was expecting and a great learning experience.

I shall study your answer in greater detail and try to manipulate it to fit my scenario. Regarding dropping of money, I think I can get away with just preventing that. It’s a really short story and doesn’t need to be too complicated.

Thanks again!

Glad to help. As you probably know, you can just write:

```Instead of dropping firnlots, say "No! You mustn't part with your precious money! You clutch your purse tighter to your side." ```
or something like that. That should take care of it, but I’d have to test to make sure the player couldn’t sneakily insert the money into something or set the money on something if you have containers or supporters in the game. I don’t remember this early if those actions include dropping.

[code]Instead of inserting firnlots into something, say “Noooo!”

Instead of putting firnlots on something, say “Nevar!”[/code]

If inform doesn’t like those, the way you check is to play the game with actions on (type ACTIONS ON while playing) and try the action, it should tell you the exact action name it’s doing and that you would need to block with your instead.

Thanks so much for all your help.

The only thing I couldn’t see in your code was how it was managing the number of firnlots (it just seems to alter the cash variable).

However, I’m learning quickly and had another look at the documentation… especially The Facts Were These example (http://inform7.com/learn/man/ex135.html#e135)… and I managed to put this together…

[code]The innkeeper can be satisfied or unsatisfied.
The innkeeper is unsatisfied.

Understand “give [things preferably held] to [someone]” as multi-giving it to.
multi-giving it to is an action applying to two things.

The selectively announce items from multiple object lists rule is listed instead of the announce items from multiple object lists rule in the action-processing rules.
This is the selectively announce items from multiple object lists rule:
if multi-giving:
do nothing;
otherwise:
if the current item from the multiple object list is not nothing:
say “[current item from the multiple object list]: [run paragraph on]”.

The before-generation rule is listed before the generate action rule in the turn sequence rules.
This is the before-generation rule:
now the innkeeper is unsatisfied.

First check multi-giving firnlots to the innkeeper:
if the innkeeper is satisfied:
stop the action;
if the innkeeper has 5 firnlots:
now the innkeeper is satisfied;
say “‘You already have what you came for, now be off with you.’ says the innkeeper.” instead;
let L be the multiple object list;
if number of entries in L < 5:
say “The innkeeper scoffs at your offer, ‘FIVE firnlots I said!’”;
now the innkeeper is satisfied;
stop the action;

Carry out multi-giving firnlots to the innkeeper:
try silently giving noun to the second noun;

After giving a firnlot to the innkeeper:
if the innkeeper has 5 firnlots:
now the iron key is carried by the player;
now the innkeeper is satisfied;
say “‘Very well then,’ says the innkeeper, ‘you can borrow my ladder but you had better bring it back in one piece. Here’s the key to remove the padlock.’” instead.[/code]

Which seems to work well so far… although it does allow me to give the innkeeper one coin at a time, which I probably don’t want so I’ll tweak it some more.

Cheers.
Chris.

Cool, glad you figured it out. You said this was a simple game so you probably wont have any trouble. In an extensive game you will run into the issue that creating independent objects for something like coins will become a headache as you need to create enough coins beforehand for every interaction in the world, and each of those independent objects becomes difficult to disambiguate “Which coin do you want to flip?” as you’ve found. If you start writing rules like “A thing can be smudged,” each of those coins is going to take on that adjective and you could run into some weird memory issues because Inform has to keep track of every coin as a potential independent object.