As I continue to work on my IF, I’m running into an issue creating a system to be able to buy items. I started this yesterday, trashed everything I wrote yesterday earlier today and am restarting. I asked about this yesterday in another thread, but I think the changes I made today render most that advice unusable. I’m doing a series of checks prior to actually buying everything and am getting stuck determining if the player has enough coins.
So, this is what I’m having issues with:
The price is a kind of value. 999 silver specifies a price. A thing has a price. The price of a thing is usually 0 silver. [I found this on an old forum post and it seems to work]
A silver coin is a thing.
Definition: a thing is affordable if the player encloses silver coins that are at least the price.
Check buying something:
if the noun is not affordable:
say "You do not have enough silver coins to buy a [noun]!".
A tankard of ale is a thing. It is drinkable. It is on sale. The price of a tankard of ale is 1 silver. The plural of tankard of ale is tankards of ale. The description is "A frothy tankard of ale. It looks refreshing." [This is how price is set.]
There are four tankards of ale.
My best guess here is that Inform does not like me trying to compare “silver coins” to “silver” because the price is silver, not silver coins, but I’m unsure how to otherwise do it.
I tried changing everything from silver to silver coins (eg, “999 silver coins specify a price”) and then get far more errors; I don’t believe I can do it that way, as a price cannot be in silver coins because silver coins are an object, not a value.
I’m assuming the actual buying routine will need to be like (in pseudo code because I’m honestly not sure how to do this part.)
Carry out buying something:
now the player has price of the noun less silver coins;
now the player is carrying the noun;
now the price of the noun player carries is 0. [This is because they can't pick up anything with a price.]
[due to multiple checks not shown, it shouldn't ever get to this point unless the shop is in-stock and they're actually in a store, so I shouldn't need to check anything in the Carry Out buying rules.]
Report buying something:
say "You have bought a [noun]!".
This system has some problems: primarily I got rid of a prompt asking what item the player wanted to buy so now the player needs to know what is for sale, but it’ll be written on a board somewhere. There will be more items than just the ale, I’m only listing one as an example.
So, any advice on how to make this work? I feel like I’m quite close.