| Chapter 14: Units |

| 14.9. The parts of a number specification

We often need to break up a number specification into its pieces. For instance, suppose we want to know the dollars part of $1.99? We can do this by naming the parts:

> A monetary value is a kind of value. $1.99 specifies a monetary value with parts dollars and cents.

We can now find the relevant parts like so. Suppose that "sum" is a monetary value. Then:

> dollars part of sum
> cents part of sum

are both numbers, so for instance we can

> say "Looks like around [dollars part of sum in words] dollar[s]."

We can also go the other way:

> monetary value with dollars part 4 cents part 72

produces the monetary value $4.72. (Note the lack of commas or "and"s, and that the parts have to be given in the right order.) This is really intended to be useful when we manipulate such values in unusual ways:

> An aspect ratio is a kind of value. 16:20 specifies an aspect ratio with parts width and height.

> To decide which aspect ratio is the wider version of (AR - an aspect ratio):
> let W be the width part of AR multiplied by 2;
> let H be the height part of AR;
> let the wider ratio be the aspect ratio with width part W height part H;
> decide on the wider ratio.

Declaring the parts of a number specification individually also enables us to tack one or more options onto any of the parts:

> A monetary value is a kind of value. $1.99 specifies a monetary value with parts dollars and cents (optional, preamble optional).

This declares that the "cents" part is optional - it will be 0 if not specified - and that if omitted, the non-numeric "preamble" before it should also be omitted. Thus "$3" is now valid and equivalent to "$3.00": indeed it will be the preferred form when Inform prints out a monetary value which is an exact number of dollars. If we had said that "cents" was optional, but not said that the preamble was optional, then "$3." would have been the form - which is less satisfactory.

There is only one other option: "without leading zeros", as in the following.

> An aspect ratio is a kind of value. 16:20 specifies an aspect ratio with parts width and height (without leading zeros).

This ensures that when the ratio 4:3 is printed, it will be printed as "4:3" and not "4:03" as would otherwise happen.

198
| Example Zqlran Era 8 Creating an alternative system of time for our game, using new units.

> Suppose that our game takes place on an alien planet that does not follow Earth time. On this planet, we want to track time with different units. We also want time to advance in those units, and we want to be able to set a schedule of timed events. "Zqlran Era 8" The Barren Lavender Surface of Zql is a room. "It is late twilight on Zql. Overhead, two crescent moons, both green, mark the sluggish passage of time. A cold wind is blowing over the pale purplish ground cover, but it does not penetrate your airtight suit." A Zqlran date is a kind of value. 14-88 specifies a Zqlran date with parts zqls and frbs. Current zqlran date is a zqlran date that varies. The current zqlran date is 8-22. Previous zqlran date is a zqlran date that varies. The previous zqlran date is 8-20. When play begins: change left hand status line to "[current zqlran date], or [current zqlran date in words]". To say (Zqlra - a Zqlran date) in words: say "[zqls part of Zqlra] Z, [frbs part of Zqlra] f." Inform automatically supplies a way to say a new unit, which will look similar to the format in which we defined that unit in the first place. But we can (as shown here) create our own alternative say phrases to express the units in other ways as well. Next, we need to meddle with time advancement so that time is tracked in Zqlran date rather than in minutes. This requires borrowing a trick from a later chapter, to replace Inform's built-in time handling with an alternative time handling rule of our own: The Zqlran time rule is listed instead of the advance time rule in the turn sequence rules. This is the Zqlran time rule: increase turn count by 1; change the previous zqlran date to current zqlran date; change the current zqlran date to current zqlran date + 0-02; repeat through the Table of Zql Schedule begin; if era entry is greater than previous zqlran date and era entry is not greater than current zqlran date begin; say event entry; say paragraph break; blank out the whole row; end if; end repeat. Table of Zql Schedule
> era | event
> 8-24 | "A wisp-thin cloud blows rapidly across the face of Nepenthe, the lesser of the two green moons."
> 8-28 | "The cloud across Nepenthe clears."
Note that we could if we wished use a different device for scheduling events: this one simply prints text at scheduled eras, but we might also (for instance) make the event entry be a rule for Inform to follow, and tell Inform to carry out that rule at the scheduled time.

Previous | Contents | Next