Units and fractions

Simulated dice for role playing games
Post Reply
gandreas
Immortal
Posts: 1464
Joined: Wed Feb 04, 2004 6:02 pm
Contact:

Units and fractions

Post by gandreas » Wed Aug 21, 2013 1:33 pm

This may seem like a silly feature that I've added here, but just wait...
First, you can do math with fractions (rational numbers) - though for now they have be enclosed in quotes (this may need to change):

Code: Select all

"3 1/2" + "1 1/8"
will evaluate to "4 5/8"

Might be mildly useful, but very few RPGs use fractions in the first place.

However, I've added the ability to take those above rational numbers and definite a "unit" for them. A simple unit would be "feet", so:

Code: Select all

"3 1/2 feet" + "1 1/8 feet"
will evaluate to "4 5/8 feet"

Again, not all that interesting, until we also define a unit "inches" which is 1/12th of a foot.

That's more interesting, but again, not a lot of RPGs deal with feet and inches.

There is something, however, that pretty much all (fantasy) RPGs deal with: coins! So we add the following XML to the character sheet:

Code: Select all

<units family="currency" id="gold piece" abbreviation="gp"/>
<units family="currency" id="silver piece" abbreviation="sp" base="gold piece" scale="1/10"/>
<units family="currency" id="copper piece" abbreviation="cp" base="gold piece" scale="1/100"/>
<units family="currency" id="electrum piece" abbreviation="ep" base="gold piece" scale="2"/>
<units family="currency" id="platinum piece" abbreviation="pp" base="gold piece" scale="10"/>
and now we can do:

Code: Select all

"3 1/2 gp" + "6 1/2 sp"
and get "4 3/20 gp" (since it will be in terms of the left unit). We then add the function "makechange()", which takes a value (with a unit) and then (optional) coarse unit and fine unit (for starting/ending) and then:

Code: Select all

makechange(“3 1/2 gp” + “6 1/2 sp”)
evaluates to "4 gp, 1 sp, 5 cp"

Code: Select all

makechange(“3 1/2 gp” + “6 1/2 sp”,"cp")
evaluates to "415 cp"

Uranium Dragon
Honored
Posts: 133
Joined: Sat Oct 09, 2010 9:42 am
IQ Test: Orange

Re: Units and fractions

Post by Uranium Dragon » Thu Aug 22, 2013 4:53 am

interesting. Could be useful in random coin rolls for when my rogue goes on a pick pocket ramage.

Post Reply