For the past few days, I’ve been trying to hack together a system wherein the player can buy things. I’ve cribbed a whole bunch from the Nickel and Dimed example in the Recipe book, but am running into issues because whereas that example uses currency and has multiple types of currency (bills and coins), I only have one, silver coins. This completely changes how you pay for items because you don’t have to worry about change or making sure merchants always have money on them. (Unless I implement selling items, I guess.)
Anyway, I cannot figure out a way to take money from the player. I’ve been working on this for hours. (No exaggeration, I promise.) No matter what I try, I have problems. After googling, checking old forum posts, reading the documentation that comes with Inform, I thought I got it but I don’t. Here’s some code:
The price is a kind of value. 10 tael specifies a price. A thing has a price. The price of a thing is usually 0 tael. [This is taken almost verbatim from Nickel and Dimed, except I'm basing the entire currency system around "tael" in case I ever have multiple denominations, their value can be expressed in tael.]
Money is a kind of thing. A coin is a kind of money.
A silver is a kind of coin. The price of a silver is 1 tael. The description is "This is a standard silver coin, engraved with the face in profile of Emperor Otto on the obverse and the Imperial palace on the reverse."
A tankard of ale is a kind of thing. It is drinkable. The price of a tankard of ale is 1 tael. The plural of tankard of ale is tankards of ale. The description is "A frothy tankard of ale. It looks refreshing."
[A 'check buying something' statement that I don't believe is relevant goes here to make sure the item is for sale and the player has enough silver. If Carry Out Buying fires, then it'd be a valid sale.]
Carry out buying something:
let total be the price of the noun understood as a number;
repeat with coin running through silver enclosed by the player:
if total is greater than 0:
now a random silver enclosed by the player is nowhere;
decrease total by 1;
try taking inventory.
I get the following error in Inform when I try to run that:
Problem. In the sentence 'let total be the price of the noun understood as a number' , I was expecting to read a value, but instead found some text that I couldn't understand - 'price of the noun understood as a number'.
I was trying to match one of these phrases:
1. let (total - a new name) be (price of the noun understood as a number - description of relations of values)
2. let (total - a new name) be (price of the noun understood as a number - name of kind)
3. let (total - a new name) be (price of the noun understood as a number - value)
4. let (total - a temporary named value) be (price of the noun understood as a number - value)
I recognised:
total = a non-temporary variable, holding a number
But I didn't recognise 'price of the noun understood as a number'.
Carry Out Buying is where the issue is, it seems. I initially tried to deduct value (eg, “remove price of the noun from the player’s value in tael”) but that, uh, really did not work. Eventually, I decided what I’m trying to do is remove 1 silver per tael of value and that’s where I run into the issue. To be clear, I have other items that cost more, necessitating some way to identify the cost. I just included one item as an example of how they’re defined in case it’s relevant.
“total” is not a number, it’s actually “1 tael” (or 2 tael, or 5 tael, etc.) and inform can’t use that to power a loop. I was hoping I could do the equivalent of something like ATOI (Ascii to Integer) in C and just turn the ASCII “1” into the number 1 and loop based on that. Searching for that turned out the “understood as a number” thing, but Inform does not like that either. (I do have a guess that the “tael” on the end may be messing things up and I may need to find a way to get rid of it before “understood as a number” will work? Inform does not seem to be good at string manipulation, so not sure if that’s even possible.)
I’ve completely stumped here. Any advice on how to make this work?
(As an aside, if anyone is wondering what a “tael” is, I heard it in a Shaw Brothers movie from the 70s and it’s apparently defined as the value of a certain quantity of silver, which seemed fitting given I was using silver coins.)
As always, thank you for putting up with my constant barrage of questions.
EDIT: As soon as I got into bed (as it’s very late), I just had a thought: Define the number of loops needed in the item definition, Add something like “Loopvalue is a number that varies.” and “The loopvalue of a tankard of ale is 1.” I don’t even need to implement tael. Just define how many times a loop needs to run that deducts silver coins to cover the price. I feel so dumb for not thinking of that before. I’ll leave this up in case anyone has any other ideas.