Hi, I’m working on a fantasy-themed game and I thought I’d put in a bit more complex currency system, with several different values (e.g. gold, silver, and copper pieces) and I’d like it to be reported a bit sensibly. Right now, I have
[code]A currency is a kind of value.
1 okram specifies a currency.
1 ura specifies a currency scaled down by 12.
1 lesut specifies a currency scaled down by 120.
1 okram 11 ura 9 lesut specifies a currency with parts okram, ura, and lesut.
A thing has a currency called price.
The verb to cost (it costs, they cost, it cost, it is costing, it has cost) implies the price property.[/code]
But if I say:
A knife costs 13 ura.
it reports the knife as costing 1.088 okram, instead of 1 okram 1 ura (ideally, but I’d be happy with even 1 okram 1 ura 0 lesut).
I don’t believe there’s an automatic way to handle this. However, you can fix this with “to say” phrase.
You can take advantage of the fact that Inform divides and ignores remainders, so
(your price) / (1 okram) = # okrams in your price
The number of ura in your price is price, minus the number of okrams, divided by a ura. The number of lesut is your price minus the okrams and ura, divided by a lesut. (I didn’t write out the lesut in the example below, but that’s the right equation.)
It’s easy enough to get the game to say “[number of okrams] okram [number of ura] ura [number of lesut] lesut” from this. It’s a little more difficult getting the proper spacing and stuff if you don’t want the zeros reported, but it can be done, if you’re willing to test a load of values.
The example below works properly for okram and ura, but doesn’t incorporate the additional complication of lesut.
To say (target - a currency):
let O be (target divided by 1 okram);
let U be (target minus (O multiplied by 1 okram)) divided by 1 ura;
say "[if O is less than 1][otherwise][O] okram[end if][if U is less than 1][otherwise] [no line break]"; [you'd need an additional test for lesut here to properly space]
say "[if U is less than 1][otherwise][U] ura[end if]"; [and another test here]
[code]A currency is a kind of value.
1 okram specifies a currency.
1 ura specifies a currency scaled down by 12.
1 lesut specifies a currency scaled down by 120.
1 okram 11 ura 9 lesut (in full) specifies a currency with parts okram, ura, and lesut (optional).
A thing has a currency called price.
The verb to cost (he costs, they cost, he costed, it is costed, it is costing) implies the price property.
The knife costs 13 ura.
Instead of examining the knife: say “This knife costs [price of the knife in full].”[/code]
That, for some reason, gives 0.088 okram 0 ura 1 lesut. I’m thinking I might have a wrong scaling somewhere, but maths and me aren’t really good friends.