Skip to content

Instantly share code, notes, and snippets.

@ezod
Created September 23, 2013 00:10
Show Gist options
  • Save ezod/6665107 to your computer and use it in GitHub Desktop.
Save ezod/6665107 to your computer and use it in GitHub Desktop.
Inform 7 extension which substitutes the English name of integral numbers in text for more natural-looking dialogue.
Version 1 of Number to English by Aaron Mavrinac begins here.
"Substitute the English name of integral numbers for more natural-looking dialogue."
Table of English Numbers
Integer English Name
0 "zero"
1 "one"
2 "two"
3 "three"
4 "four"
5 "five"
6 "six"
7 "seven"
8 "eight"
9 "nine"
10 "ten"
11 "eleven"
12 "twelve"
13 "thirteen"
14 "fourteen"
15 "fifteen"
16 "sixteen"
17 "seventeen"
18 "eighteen"
19 "nineteen"
20 "twenty"
30 "thirty"
40 "forty"
50 "fifty"
60 "sixty"
70 "seventy"
80 "eighty"
90 "ninety"
To lowsay (item - a number):
if item is less than 1000:
let hundreds be given by hundreds = item / 100 where hundreds is a number;
if hundreds is greater than 0:
say "[the english name corresponding to an integer of hundreds in the Table of English Numbers] hundred";
now item is item - (100 * hundreds);
if item is greater than 0:
if hundreds is greater than 0:
say " ";
if there is an english name corresponding to an integer of item in the Table of English Numbers:
say "[the english name corresponding to an integer of item in the Table of English Numbers]";
otherwise:
let tens be given by tens = 10 * (item / 10) where tens is a number;
let ones be given by ones = item - tens where ones is a number;
say "[the english name corresponding to an integer of tens in the Table of English Numbers]-[the english name corresponding to an integer of ones in the Table of English Numbers]".
To say (item - a number):
if item is 0:
say "[the english name corresponding to an integer of item in the Table of English Numbers]";
if item is less than 1000000:
let thousands be given by thousands = item / 1000 where thousands is a number;
if thousands is greater than 0:
lowsay thousands;
say " thousand";
now item is item - (1000 * thousands);
if item is greater than 0:
if thousands is greater than 0:
say " ";
lowsay item;
otherwise:
say "[item]".
To say (item - a number) in sentence case:
say "[item]" in sentence case.
Number to English ends here.
---- DOCUMENTATION ----
This simple extension replaces printed integers in text substitutions with their English name equivalents, for more natural-looking dialogue.
Any number in square brackets will automatically be converted to the full English name:
When play begins:
say "I can say [0], [12], [24], [200], [4444], [8092], and even values over [9000].[paragraph break]"
let X be 817;
say "Don't you find saying [X] is more natural?"
If the number appears at the start of a sentence, it can be properly capitalized using the sentence case modifier:
When play begins, say "[57 in sentence case] fairies dance in a ring.".
Numbers over 1,000,000 are printed as usual (in numeric form).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment