(09-08-2014 11:40 PM)CosmicTruth Wrote: [ -> ]... so can you show me a little code to just change between 2 units using custom units? ...
I will try my very best! Let's take the money conversion from the Harry Potter universe: The wizards use a strange system of
Galleons, Sickles, and Knuts, whereas
1 Galleon = 17 Sickles
1 Sickle = 29 Knuts (thus 1 Galleon = 493 Knuts)
BTW, the relation to the "real" world is given by 1 Galleon ~ £5, thus 1 Knut ~ 1 Penny.
You would implement this as follows:
Start with a new directory, e.g. Potter, and change into it via keypress of the according softkey in the vars menu:
'Potter' CRDIR Potter
Now define the new units creating variables with appropriate name, and value. Lets start with Knuts, which we define via Sickles, knowing that one Knut is 1/29 Sickle:
'3.44827586207E-2_Sickles' 'Knuts' STO>
Next for Sickles, defined as 1/17 Galleon:
'5.88235294118E-2_Galleons' 'Sickles' STO>
And for the conversion to real world:
'5.0_£' 'Galleons' STO>
But finally you have to declare the "basic" unit within this system, otherwise you will get an "Invalid Unit" error. I choose the GBP. This is accomplished the following way:
'1_?' '£' STO>
It's clear that there may be one and only one basic unit defined. Therefore you need for every unit system it's own directory!
To start the conversions, you need finally a special custom menu:
{ '1_Knuts' '1_Sickles' '1_Galleons' '1_£' } 'CST' STO>
And now simply call CUSTOM (left-shift MODE key). After that, you convert the usual way via softkey and left-shift-softkey, e.g.
Enter 10 softkey '£', you will have 10_£ on the stack.
left-shift softkey Galleons will give 2_Galleons on the stack.
left-shift softkey Sickles will give 34_Sickles on the stack.
How much is 2 Galleons 4 Sickles 11 Knuts? I omit the word softkey:
2 Galleons 4 Sickles + 11 Knuts + ends up in 1113._Knuts
left-shift £ gives ~ 11.29_£
BTW, we see the big advantage of the decimal system. SI prefixes may simply added when needed. So you may key in e.g. 1000 kilo-Knuts:
1000._kKnuts
which converts via left-shift £ to ~ 10142_£
Hope that helps,
Ralf.